Submission #104795

#TimeUsernameProblemLanguageResultExecution timeMemory
104795ShtefDijamant (COI16_dijament)C++14
100 / 100
1957 ms52260 KiB
#include <iostream> #include <map> #include <vector> #include <utility> #include <algorithm> using namespace std; typedef pair <int, string> psi; #define x first #define y second #define mp make_pair map <string, bool> m; map <string, int> dth; map <string, map <psi, bool, greater <psi> > > svi; int n; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 0 ; i < n ; ++i){ string s; cin >> s; char poc; cin >> poc; map <string, bool> ovaj; while(1){ string x; cin >> x; if(x == ";") break; ovaj[x] = 1; } if(m.find(s) != m.end()){ cout << "greska" << endl; continue; } bool p = 1; int sad = 0; map <psi, bool, greater <psi> > taj; for(map <string, bool>::iterator j = ovaj.begin() ; j != ovaj.end() ; ++j){ string x = j->x; if(m.find(x) == m.end()){ p = 0; break; } sad = max(sad, dth[x] + 1); taj[mp(dth[x], x)] = 1; } /* for(map <psi, bool>::iterator j = taj.begin() ; j != taj.end() ; ++j){ psi o = j->x; cout << o.y << " : " << o.x << endl; } */ if(!p){ cout << "greska" << endl; continue; } map <string, bool> gornji; for(map <psi, bool>::iterator j = taj.begin() ; j != taj.end() ; ++j){ string x = (j->x).y; if(gornji.find(x) != gornji.end()) continue; for(map <psi, bool>::iterator v = svi[x].begin() ; v != svi[x].end() ; ++v){ string y = (v->x).y; if(gornji.find(y) != gornji.end()){ p = 0; break; } gornji[y] = 1; } if(!p) break; } if(!p){ cout << "greska" << endl; continue; } cout << "ok" << endl; m[s] = 1; dth[s] = sad; gornji.clear(); for(map <psi, bool>::iterator j = taj.begin() ; j != taj.end() ; ++j){ string x = (j->x).y; if(svi[s].find(mp(dth[x], x)) != svi[s].end()) continue; svi[s][mp(dth[x], x)] = 1; for(map <psi, bool>::iterator v = svi[x].begin() ; v != svi[x].end() ; ++v){ string y = (v->x).y; svi[s][mp(dth[y], y)] = 1; } } //cout << endl << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...