Submission #1120381

#TimeUsernameProblemLanguageResultExecution timeMemory
1120381vjudge1KOVANICE (COI15_kovanice)C++17
0 / 100
534 ms524288 KiB
// Ali // #pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long int #define ins insert #define pii pair<int,int> #define pb push_back #define endl '\n' #define putr(x) cout<<x<<endl;return; #define all(x) x.begin(),x.end() const int mod = 1e9 +7, sze = 3e5+23, inf = 2e9, LG = 19,pr = 31; int val[sze]; struct lan{ vector<int> parent; vector<int> sz; lan(int n){ parent.resize(n+23); iota(all(parent),0); sz.resize(n+23,1); } int root(int a){ if(parent[a]==a){ return a; } return parent[a]=root(parent[a]); } void unite(int a,int b){ int x = root(a); int y = root(b); if(x!=y){ if(sz[x]<sz[y]){ swap(x,y); } sz[x]+=sz[y]; parent[y]=x; } } }; void fast(){ int n,m,qq; cin>>n>>m>>qq; vector<pair<pii,char>> q; bool flag=false; while(qq--){ string s; cin>>s; string a=""; string b=""; char op; for(auto v:s){ if(v=='<' || v=='='){ op = v; swap(a,b); } else{ a+=v; } } swap(a,b); q.pb({{stoll(a),stoll(b)},op}); // cout<<a<<" "<<op<<" "<<b<<endl; if(op=='<' && !flag){ flag=true; } } lan dsu(n+23); if(flag){ map<int,vector<int>> same; map<int,set<int>> lst; for(auto [vv,op]:q){ int a = vv.first; int b = vv.second; if(op=='<'){ if(val[a] || val[b]){ val[a]=-1; val[b]=-1; } else{ val[a]=1; val[b]=2; } } else{ dsu.unite(a,b); } } for(int i =1;i<=m;i++){ same[dsu.root(i)].pb(i); if(val[i]){ if(val[i]==-1){ lst[dsu.root(i)].ins(INT_MAX); lst[dsu.root(i)].ins(INT_MAX-1); } lst[dsu.root(i)].ins(val[i]); } } for(auto [k,v]:same){ if(lst[k].size()==1){ for(auto x:v){ val[x]=*lst[k].begin(); } } } } for(int i=1;i<=m;i++){ if(val[i]<=0){ cout<<"?"<<endl; } else{ cout<<"K"<<val[i]<<endl; } } } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; // cin>>tt; while(tt--){ fast(); } 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...