Submission #1518192
Source Code Expand
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define rng(a) a.begin(),a.end() #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define pb push_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcount #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define df(x) int x = in() #define dame { puts("-1"); return 0;} #define show(x) cout<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,vector<T>,greater<T> > #define bn(x) ((1<<x)-1) #define newline puts("") #define v(T) vector<T> #define vv(T) vector<vector<T>> using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; inline int in() { int x; scanf("%d",&x); return x;} inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');} template<typename T>istream& operator>>(istream&i,vector<T>&v) {rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(const vector<T>&v) {stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,const vector<T>&v) {if(sz(v))o<<join(v);return o;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v) {return i>>v.fi>>v.se;} template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v) {return o<<v.fi<<","<<v.se;} const int MX = 200005, INF = 1001001001; const ll LINF = 1e18; const double eps = 1e-10; vi to[MX]; vi t; int ui; vi used, vs; int dfs(int v, int p=-1) { if (used[v] == ui) return v; if (used[v]) return -1; used[v] = ui; rep(i,sz(to[v])) { int u = to[v][i]; if (u == p) continue; int r = dfs(u,v); if (r == -1) continue; vs.pb(v); if (v == r) return -1; return r; } return -1; } int gfs(int v, int p=-1) { set<int> s; rep(i,sz(to[v])) { int u = to[v][i]; if (u == p || t[u]) continue; int r = gfs(u,v); s.insert(r); } for (int i = 0;; ++i) { if (s.count(i)) continue; return i; } } int main() { int n; scanf("%d",&n); rep(i,n) { int p; scanf("%d",&p); --p; to[p].pb(i); } used = vi(n); ui = 1; rep(i,n) if (!used[i]) { dfs(i); ++ui; if (sz(vs)) break; } t = vi(n); for (int v : vs) t[v] = 1; int m = sz(vs); v(set<int>) s(m); rep(i,m) { int v = vs[i]; for (int u : to[v]) { if (t[u]) continue; s[i].insert(gfs(v)); } } vi c; for (int i = 0; sz(c) < 2; ++i) { if (s[0].count(i)) continue; c.pb(i); } s.pb(s[0]); for (int x0 : c) { int x = x0; rrep(i,n) { int j = 0; for (; j == x || s[i].count(j); ++j); x = j; } if (x == x0) { puts("POSSIBLE"); return 0; } } puts("IMPOSSIBLE"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Namori Grundy |
User | snuke |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 3315 Byte |
Status | RE |
Exec Time | 252 ms |
Memory | 37876 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:86:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:89:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&p); ^
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 800 | ||||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0, example1, example2, example3 |
All | example0, example1, example2, example3, loop0, loop1, loop10, loop11, loop12, loop13, loop14, loop15, loop16, loop17, loop18, loop19, loop2, loop3, loop4, loop5, loop6, loop7, loop8, loop9, loopex0, loopex1, loopex10, loopex11, loopex12, loopex13, loopex14, loopex15, loopex16, loopex17, loopex18, loopex19, loopex2, loopex20, loopex21, loopex22, loopex23, loopex3, loopex4, loopex5, loopex6, loopex7, loopex8, loopex9, rand0, rand1, rand2, rand3, rand4, rand5, rand6, rand7, rand8, rand9, small0, small1, small2, small3, small4, small5, small6, small7, small8, small9 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example0 | AC | 3 ms | 4864 KB |
example1 | AC | 3 ms | 4992 KB |
example2 | AC | 3 ms | 4992 KB |
example3 | RE | 96 ms | 4864 KB |
loop0 | RE | 214 ms | 9472 KB |
loop1 | RE | 216 ms | 9472 KB |
loop10 | RE | 214 ms | 9600 KB |
loop11 | RE | 219 ms | 9472 KB |
loop12 | RE | 213 ms | 9472 KB |
loop13 | RE | 213 ms | 9600 KB |
loop14 | RE | 215 ms | 9472 KB |
loop15 | RE | 213 ms | 9472 KB |
loop16 | RE | 214 ms | 9600 KB |
loop17 | RE | 214 ms | 9472 KB |
loop18 | RE | 217 ms | 9472 KB |
loop19 | RE | 214 ms | 9472 KB |
loop2 | RE | 221 ms | 9600 KB |
loop3 | RE | 214 ms | 9472 KB |
loop4 | RE | 214 ms | 9472 KB |
loop5 | RE | 215 ms | 9472 KB |
loop6 | RE | 214 ms | 9600 KB |
loop7 | RE | 213 ms | 9600 KB |
loop8 | RE | 214 ms | 9600 KB |
loop9 | RE | 215 ms | 9472 KB |
loopex0 | RE | 229 ms | 9472 KB |
loopex1 | RE | 238 ms | 9344 KB |
loopex10 | RE | 237 ms | 9344 KB |
loopex11 | RE | 246 ms | 9344 KB |
loopex12 | RE | 238 ms | 9344 KB |
loopex13 | RE | 234 ms | 9344 KB |
loopex14 | RE | 233 ms | 9344 KB |
loopex15 | RE | 236 ms | 9344 KB |
loopex16 | RE | 241 ms | 9472 KB |
loopex17 | RE | 234 ms | 9344 KB |
loopex18 | RE | 241 ms | 9472 KB |
loopex19 | RE | 234 ms | 9344 KB |
loopex2 | RE | 234 ms | 9344 KB |
loopex20 | RE | 230 ms | 9344 KB |
loopex21 | RE | 233 ms | 9472 KB |
loopex22 | RE | 236 ms | 9472 KB |
loopex23 | RE | 239 ms | 9344 KB |
loopex3 | RE | 239 ms | 9344 KB |
loopex4 | RE | 228 ms | 9472 KB |
loopex5 | RE | 236 ms | 9472 KB |
loopex6 | RE | 252 ms | 9344 KB |
loopex7 | RE | 236 ms | 9472 KB |
loopex8 | RE | 235 ms | 9472 KB |
loopex9 | RE | 234 ms | 9472 KB |
rand0 | RE | 114 ms | 9088 KB |
rand1 | RE | 123 ms | 11264 KB |
rand2 | AC | 9 ms | 8448 KB |
rand3 | RE | 149 ms | 19840 KB |
rand4 | AC | 73 ms | 37876 KB |
rand5 | RE | 131 ms | 11392 KB |
rand6 | AC | 15 ms | 10112 KB |
rand7 | AC | 6 ms | 6144 KB |
rand8 | RE | 139 ms | 19196 KB |
rand9 | WA | 5 ms | 6272 KB |
small0 | RE | 97 ms | 4864 KB |
small1 | WA | 3 ms | 4864 KB |
small2 | WA | 3 ms | 4992 KB |
small3 | WA | 3 ms | 4992 KB |
small4 | AC | 3 ms | 4992 KB |
small5 | AC | 2 ms | 4992 KB |
small6 | AC | 2 ms | 4992 KB |
small7 | WA | 3 ms | 4992 KB |
small8 | AC | 3 ms | 4992 KB |
small9 | WA | 3 ms | 4992 KB |