Submission #576926

#TimeUsernameProblemLanguageResultExecution timeMemory
576926MounirKOVANICE (COI15_kovanice)C++14
100 / 100
718 ms80856 KiB
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define sz(x) (int)x.size() #define pb push_back #define pii pair<int, int> #define chmin(x, v) x = min(x, v) #define chmax(x, v) x = max(x, v) #define print(x) cout << #x << " est " << x << endl; #define x first #define y second #define int long long using namespace std; const int N = 1e6; int ens[N]; int getEns(int noeud){ if (ens[noeud] != noeud) ens[noeud] = getEns(ens[noeud]); return ens[noeud]; } vector<int> petits[N], gros[N]; int maxChemin[N]; vector<int> ordre; bool vu[N]; bool isWin[N]; int dfs(int noeud){ if (!vu[noeud]){ vu[noeud] = true; for (int petit : petits[noeud]) chmax(maxChemin[noeud], dfs(petit)); maxChemin[noeud]++; ordre.pb(noeud); } return maxChemin[noeud]; } signed main(){ int nTypes, nPieces, nMesures; cin >> nTypes >> nPieces >> nMesures; for (int i = 0; i < nPieces; ++i) ens[i] = i; vector<pii> aretes; for (int i = 0; i < nMesures; ++i){ int first, second; char op; cin >> first >> op >> second; --first; --second; if (op == '=') ens[getEns(first)] = getEns(second); else if (op == '<') aretes.pb({second, first}); else aretes.pb({first, second}); // cout << "salut" << endl; } for (pii arete : aretes){ petits[getEns(arete.first)].pb(getEns(arete.second)); gros[getEns(arete.second)].pb(getEns(arete.first)); } for (int i = 0; i < nPieces; ++i){ if (ens[i] != i) continue; isWin[i] = (dfs(i) == nTypes); } reverse(all(ordre)); for (int cur : ordre) for (int apres : gros[cur]) isWin[cur] |= (isWin[apres] && maxChemin[apres] == maxChemin[cur] + 1); for (int iPiece = 0; iPiece < nPieces; ++iPiece){ int nod = getEns(iPiece); if (isWin[nod] || maxChemin[nod] > nTypes) cout << "K" << min(nTypes, maxChemin[nod]) << endl; else cout << "?" << 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...