Submission #1077078

#TimeUsernameProblemLanguageResultExecution timeMemory
1077078TrentBeech Tree (IOI23_beechtree)C++17
14 / 100
43 ms6992 KiB
#include "beechtree.h" #include "bits/stdc++.h" using namespace std; #define forR(i, x) for(int i = 0; i < (x); ++i) #define REP(i, a, b) for(int i = (a); i < (b); ++i) #define all(x) x.begin(), x.end() #define asst(x) if(!(x)) exit(2) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; vi sub(int T, vi& P) { set<int> in; in.insert(T); int N = P.size(); while(true) { bool hasNew = false; forR(i, N) { if(in.count(P[i]) && !in.count(i)) { hasNew = true; in.insert(i); } } if(!hasNew) break; } vi ret; for(int i : in) ret.push_back(i); return ret; } std::vector<int> beechtree(int N, int M, std::vector<int> P, std::vector<int> C) { vi ret(N); if(N <= 8) { forR(r, N) { vi v = sub(r, P); sort(all(v)); bool found = false; do { bool can = v[0] == r; map<int, int> freq; REP(i, 1, v.size()) { can = can && (P[v[i]] == v[freq[C[v[i]]]]); freq[C[v[i]]] += 1; } found = found || can; } while(next_permutation(all(v))); ret[r] = found ? 1 : 0; } return ret; } bool can = true; int lasCol = -1; for(int i = N-1; i >= 0; --i) { if(can) { ret[i] = 1; if(lasCol == -1) lasCol = C[i]; else can = can && C[i] == lasCol; } else { ret[i] = 0; } } return ret; }

Compilation message (stderr)

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
      |                                         ^
beechtree.cpp:44:17: note: in expansion of macro 'REP'
   44 |                 REP(i, 1, v.size()) {
      |                 ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...