Submission #715121

#TimeUsernameProblemLanguageResultExecution timeMemory
715121justinhall363Carnival (CEOI14_carnival)C++14
20 / 100
102 ms328 KiB
#include <iostream> #include <vector> #include <set> #include <map> using namespace::std; #define FOR(i, b) for(int i = 0; i < b; i++) #define F0R(i, a, b) for(int i = a; i <= b; i++) int N; vector<int> e; int get(int x){ return e[x] < 0 ? x : e[x] = get(e[x]); } void unite(int x, int y){ x = get(x), y = get(y); if(x == y) return; if(e[x] > e[y]) swap(x, y); e[x] += e[y]; e[y] = x; } int query(int i0, int iN){ //ask grader how many cout<<iN-i0+1<<" "; F0R(i, i0, iN-1) cout<<i+1<<" "; cout<<iN+1<<endl; int diff; cin>>diff; return diff; } void check(int i0, int iN){ //i limits inclusive if(i0 == iN) return; //only 1 int diff = query(i0, iN); if(diff == 1){ //all same costume F0R(i, i0+1, iN) unite(i0, i); return; } if(iN-i0 == 1) return; //2 left don't need to check //split in half int half = i0+(iN-i0)/2; check(i0, half); check(half+1, iN); set<int> cc1, cc2; //cc reps of first half and second half F0R(i, i0, half) cc1.insert(get(i)); F0R(i, half+1, iN) cc2.insert(get(i)); vector<int> used(N); for(int c1 : cc1){ //check for overlaps for(int c2 : cc2){ if(c1 == c2 || used[c2]) continue; cout<<2<<" "<<c1+1<<" "<<c2+1<<endl; int q; cin>>q; if(q == 1){ unite(c1, c2); used[c1] = true; used[c2] = true; break; } //found same costume } } } int main() { //freopen("carnival.in", "r", stdin); //freopen("carnival.out", "w", stdout); cin>>N; e = vector<int>(N, -1); check(0, N-1); //convert to costume #s map<int, int> cc; int id = 1; FOR(i, N) if(e[i] < 0){ cc[i] = id; id++; } cout<<0<<" "; FOR(i, N) cout<<cc[get(i)]<<" "; cout<<endl; }

Compilation message (stderr)

carnival.cpp: In function 'int query(int, int)':
carnival.cpp:8:22: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    8 | #define F0R(i, a, b) for(int i = a; i <= b; i++)
      |                      ^~~
carnival.cpp:22:5: note: in expansion of macro 'F0R'
   22 |     F0R(i, i0, iN-1) cout<<i+1<<" "; cout<<iN+1<<endl;
      |     ^~~
carnival.cpp:22:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   22 |     F0R(i, i0, iN-1) cout<<i+1<<" "; cout<<iN+1<<endl;
      |                                      ^~~~
#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...