Rezultati

Up. imeNalogaJezikRezultatČas oddaje
Aquasonic-2018 Prehitevanje C++ 100/100OK 04. okt '18 @ 17:59

Test Točke Porabljen spomin Porabljen čas Status
#1 16/16 3,063 MiB 0,010 s OK
#2 16/16 3,211 MiB 0,004 s OK
#3 17/17 3,051 MiB 0,000 s OK
#4 17/17 4,926 MiB 0,169 s OK
#5 17/17 39,051 MiB 0,000 s OK
#6 17/17 3,203 MiB 0,004 s OK

Ocenjevani program (main.cpp):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const ll mod = 1e18+7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
int n;
cin>>n;
vector<string> v;
vector<pair<int,int> > pr(n+1,make_pair(-1,-1));
map<string,int> m;
    for(int i=0;i<n;i++)
    {
    string s;
    cin>>s;
    m[s]=i;
    v.push_back(s);
    if(i>0&&i<n-1)
    pr[i]=make_pair(i-1,i+1);
    else if(i==n-1)
    pr[i]=make_pair(i-1,-1);
    else if(i==0)
    pr[i]=make_pair(-1,i+1);
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        string s1,s2;
        cin>>s1>>s2;
        int a=m[s1],b=m[s2];
        if(pr[a].first!=-1)
        pr[pr[a].first].second=pr[a].second;
        if(pr[a].second!=-1)
        pr[pr[a].second].first=pr[a].first;
        pr[a].first=pr[b].first;
        if(pr[b].first!=-1)
        pr[pr[b].first].second=a;
        pr[a].second=b;
        pr[b].first=a;
    }
    int poc=-1;
    for(int i=0;i<n;i++)
    {
    if(pr[i].second==-1)
    poc=i;}
    vector<string> vk;
    vk.push_back(v[poc]);
    while(pr[poc].first!=-1)
    {
    poc=pr[poc].first;
    vk.push_back(v[poc]);

    }
    reverse(vk.begin(),vk.end());
    for(int i=0;i<n;i++)
    cout<<vk[i]<<endl;
    return 0;
}