Submission #1254254

#TimeUsernameProblemLanguageResultExecution timeMemory
1254254ifugaoLight Bulbs (EGOI24_lightbulbs)C++20
Compilation error
0 ms0 KiB
include <bits/stdc++.h> using namespace std; int N; string allZero; int knownCol=-1; int test_row(int rowId,string& choice) { cout << "?" << endl; for(int i=0;i<N;i++) { if(i==rowId) cout << choice << endl; else cout << allZero << endl; } int litCells; cin >> litCells; return litCells; } int test_horizontal_aux(int row1,int row2, int col) { cout << "?" << endl; for(int i=0;i<N;i++) { if(i==row1 || i==row2) { allZero[col]='1'; cout << allZero << endl; allZero[col]='0'; } else cout << allZero << endl; } int litCells; cin >> litCells; return litCells; } bool test_horizontal(int row,int col) { for(int offset=1;offset<=2;offset++) { int litCells=test_horizontal_aux(row,(row+offset)%N,col); if(litCells==2*N) return true; else if(litCells==N) return false; } int litCells=test_horizontal_aux((row+1)%N,(row+2)%N,col); if(litCells==2*N) return false; else if(litCells==N) return true; assert(false); } bool test_horizontal2(int row,int col, int colFirst) { assert(row>0); cout << "?" << endl; for(int i=0;i<N;i++) { if(i==0) { allZero[colFirst]='1'; cout << allZero << endl; allZero[colFirst]='0'; } else if(i==row) { allZero[col]='1'; cout << allZero << endl; allZero[col]='0'; } else cout << allZero << endl; } int litCells; cin >> litCells; return (litCells==2*N); } bool test_vertical2(int row,int col, int rowKnown) { cout << "?" << endl; for(int i=0;i<N;i++) { string s(N,'0'); if(i==row) s[col]='1'; if(i==rowKnown) s[knownCol]='1'; cout << s << endl; } int litCells; cin >> litCells; return (litCells==2*N); } void full_row(int rowId) { cout << "!" << endl; for(int i=0;i<N;i++) { if(i==rowId) cout << string(N,'1') << endl; else cout << allZero << endl; } } void print_picked_row(vector<int>& picked) { cout << "!" << endl; for(int i=0;i<N;i++) { allZero[picked[i]]='1'; cout << allZero << endl; allZero[picked[i]]='0'; } } void try_print_picked_col(vector<int>& picked) { bool ok=true; for(int i=0;i<N;i++) if(picked[i]==-1) ok=false; else knownCol=i; if(!ok) return; cout << "!" << endl; for(int i=0;i<N;i++) { string row(N,'0'); for(int j=0;j<N;j++) if(picked[j]==i) row[j]='1'; cout << row << endl; } exit(0); } int cut_half(int cnt,string& choice,string& prevChoice) { int curCnt=0; for(int j=0;j<N;j++) { if(prevChoice[j]=='1' && curCnt<(cnt+1)/2) { choice[j]='1'; curCnt++; } else choice[j]='0'; } return curCnt; } void other_half(int& curCnt,string& choice,string& prevChoice) { curCnt=0; for(int j=0;j<N;j++) { if(prevChoice[j]=='1' && choice[j]=='0') { choice[j]='1'; curCnt++; } else choice[j]='0'; } } int main() { cin >> N; allZero=string(N,'0'); vector<int> pickedRow(N,-1),pickedCol(N,-1); for(int i=0;i<N;i++) { // Try noncovered row string choice(N,'0'); int cnt=0; bool safe=true; for(int j=0;j<N;j++) if(pickedCol[j]==-1) { choice[j]='1'; cnt++; } try_print_picked_col(pickedCol); if(cnt==1) { // TODO dicho on col int col=choice.find('1'); assert(knownCol!=-1); if(test_vertical2(i,col,pickedCol[knownCol])) { pickedCol[col]=i; try_print_picked_col(pickedCol); } else { pickedRow[i]=col; } } else { string prevChoice=choice; int litCells=test_row(i,choice); if(litCells==cnt*N) { for(int j=0;j<N;j++) if(choice[j]=='1') pickedCol[j]=i; try_print_picked_col(pickedCol); } while(cnt>1) { int curCnt=cut_half(cnt,choice,prevChoice); if(curCnt==1) { int col=choice.find('1'); if((i==0 && test_horizontal(i,col)) || (i>0 && test_horizontal2(i,col,pickedRow[0]))) { pickedRow[i]=col; if(safe) { for(int j=0;j<N;j++) if(prevChoice[j]=='1' && choice[j]=='0') { pickedCol[j]=i; assert(!test_horizontal(i,j)); } } try_print_picked_col(pickedCol); break; } else { pickedCol[col]=i; try_print_picked_col(pickedCol); other_half(curCnt,choice,prevChoice); } } else { litCells=test_row(i,choice); if(litCells==N) { pickedRow[i]=choice.find('1'); break; } else if(litCells==N*curCnt) { for(int j=0;j<N;j++) if(choice[j]=='1') pickedCol[j]=i; try_print_picked_col(pickedCol); other_half(curCnt,choice,prevChoice); safe=false; } else safe=true; } prevChoice=choice; cnt=curCnt; } if(cnt==1) pickedRow[i]=prevChoice.find('1'); else assert(pickedRow[i]!=-1); } } print_picked_row(pickedRow); }

Compilation message (stderr)

Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:10: error: 'bits' was not declared in this scope
    1 | include <bits/stdc++.h>
      |          ^~~~
Main.cpp:1:15: error: 'stdc' was not declared in this scope; did you mean 'std'?
    1 | include <bits/stdc++.h>
      |               ^~~~
      |               std
Main.cpp:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
Main.cpp:6:1: error: 'string' does not name a type
    6 | string allZero;
      | ^~~~~~
Main.cpp:9:24: error: 'string' has not been declared
    9 | int test_row(int rowId,string& choice)
      |                        ^~~~~~
Main.cpp: In function 'int test_row(int, int&)':
Main.cpp:11:9: error: 'cout' was not declared in this scope
   11 |         cout << "?" << endl;
      |         ^~~~
Main.cpp:11:24: error: 'endl' was not declared in this scope
   11 |         cout << "?" << endl;
      |                        ^~~~
Main.cpp:17:33: error: 'allZero' was not declared in this scope
   17 |                         cout << allZero << endl;
      |                                 ^~~~~~~
Main.cpp:20:9: error: 'cin' was not declared in this scope
   20 |         cin >> litCells;
      |         ^~~
Main.cpp: In function 'int test_horizontal_aux(int, int, int)':
Main.cpp:26:9: error: 'cout' was not declared in this scope
   26 |         cout << "?" << endl;
      |         ^~~~
Main.cpp:26:24: error: 'endl' was not declared in this scope
   26 |         cout << "?" << endl;
      |                        ^~~~
Main.cpp:31:25: error: 'allZero' was not declared in this scope
   31 |                         allZero[col]='1';
      |                         ^~~~~~~
Main.cpp:36:33: error: 'allZero' was not declared in this scope
   36 |                         cout << allZero << endl;
      |                                 ^~~~~~~
Main.cpp:39:9: error: 'cin' was not declared in this scope
   39 |         cin >> litCells;
      |         ^~~
Main.cpp: In function 'bool test_horizontal(int, int)':
Main.cpp:58:9: error: 'assert' was not declared in this scope
   58 |         assert(false);
      |         ^~~~~~
Main.cpp:1:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
  +++ |+#include <cassert>
    1 | include <bits/stdc++.h>
Main.cpp: In function 'bool test_horizontal2(int, int, int)':
Main.cpp:63:9: error: 'assert' was not declared in this scope
   63 |         assert(row>0);
      |         ^~~~~~
Main.cpp:63:9: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
Main.cpp:64:9: error: 'cout' was not declared in this scope
   64 |         cout << "?" << endl;
      |         ^~~~
Main.cpp:64:24: error: 'endl' was not declared in this scope
   64 |         cout << "?" << endl;
      |                        ^~~~
Main.cpp:69:25: error: 'allZero' was not declared in this scope
   69 |                         allZero[colFirst]='1';
      |                         ^~~~~~~
Main.cpp:75:25: error: 'allZero' was not declared in this scope
   75 |                         allZero[col]='1';
      |                         ^~~~~~~
Main.cpp:80:33: error: 'allZero' was not declared in this scope
   80 |                         cout << allZero << endl;
      |                                 ^~~~~~~
Main.cpp:83:9: error: 'cin' was not declared in this scope
   83 |         cin >> litCells;
      |         ^~~
Main.cpp: In function 'bool test_vertical2(int, int, int)':
Main.cpp:89:9: error: 'cout' was not declared in this scope
   89 |         cout << "?" << endl;
      |         ^~~~
Main.cpp:89:24: error: 'endl' was not declared in this scope
   89 |         cout << "?" << endl;
      |                        ^~~~
Main.cpp:92:17: error: 'string' was not declared in this scope
   92 |                 string s(N,'0');
      |                 ^~~~~~
Main.cpp:94:25: error: 's' was not declared in this scope
   94 |                         s[col]='1';
      |                         ^
Main.cpp:96:25: error: 's' was not declared in this scope
   96 |                         s[knownCol]='1';
      |                         ^
Main.cpp:97:25: error: 's' was not declared in this scope
   97 |                 cout << s << endl;
      |                         ^
Main.cpp:100:9: error: 'cin' was not declared in this scope
  100 |         cin >> litCells;
      |         ^~~
Main.cpp: In function 'void full_row(int)':
Main.cpp:106:9: error: 'cout' was not declared in this scope
  106 |         cout << "!" << endl;
      |         ^~~~
Main.cpp:106:24: error: 'endl' was not declared in this scope
  106 |         cout << "!" << endl;
      |                        ^~~~
Main.cpp:110:33: error: 'string' was not declared in this scope
  110 |                         cout << string(N,'1') << endl;
      |                                 ^~~~~~
Main.cpp:112:33: error: 'allZero' was not declared in this scope
  112 |                         cout << allZero << endl;
      |                                 ^~~~~~~
Main.cpp: At global scope:
Main.cpp:116:6: error: variable or field 'print_picked_row' declared void
  116 | void print_picked_row(vector<int>& picked)
      |      ^~~~~~~~~~~~~~~~
Main.cpp:116:23: error: 'vector' was not declared in this scope
  116 | void print_picked_row(vector<int>& picked)
      |                       ^~~~~~
Main.cpp:116:30: error: expected primary-expression before 'int'
  116 | void print_picked_row(vector<int>& picked)
      |                              ^~~
Main.cpp:127:6: error: variable or field 'try_print_picked_col' declared void
  127 | void try_print_picked_col(vector<int>& picked)
      |      ^~~~~~~~~~~~~~~~~~~~
Main.cpp:127:27: error: 'vector' was not declared in this scope
  127 | void try_print_picked_col(vector<int>& picked)
      |                           ^~~~~~
Main.cpp:127:34: error: expected primary-expression before 'int'
  127 | void try_print_picked_col(vector<int>& picked)
      |                                  ^~~
Main.cpp:148:22: error: 'string' has not been declared
  148 | int cut_half(int cnt,string& choice,string& prevChoice)
      |                      ^~~~~~
Main.cpp:148:37: error: 'string' has not been declared
  148 | int cut_half(int cnt,string& choice,string& prevChoice)
      |                                     ^~~~~~
Main.cpp: In function 'int cut_half(int, int&, int&)':
Main.cpp:153:30: error: invalid types 'int[int]' for array subscript
  153 |                 if(prevChoice[j]=='1' && curCnt<(cnt+1)/2)
      |                              ^
Main.cpp:155:31: error: invalid types 'int[int]' for array subscript
  155 |                         choice[j]='1';
      |                               ^
Main.cpp:159:31: error: invalid types 'int[int]' for array subscript
  159 |                         choice[j]='0';
      |                               ^
Main.cpp: At global scope:
Main.cpp:164:29: error: 'string' has not been declared
  164 | void other_half(int& curCnt,string& choice,string& prevChoice)
      |                             ^~~~~~
Main.cpp:164:44: error: 'string' has not been declared
  164 | void other_half(int& curCnt,string& choice,string& prevChoice)
      |                                            ^~~~~~
Main.cpp: In function 'void other_half(int&, int&, int&)':
Main.cpp:169:30: error: invalid types 'int[int]' for array subscript
  169 |                 if(prevChoice[j]=='1' && choice[j]=='0')
      |                              ^
Main.cpp:169:48: error: invalid types 'int[int]' for array subscript
  169 |                 if(prevChoice[j]=='1' && choice[j]=='0')
      |                                                ^
Main.cpp:171:31: error: invalid types 'int[int]' for array subscript
  171 |                         choice[j]='1';
      |                               ^
Main.cpp:175:31: error: invalid types 'int[int]' for array subscript
  175 |                         choice[j]='0';
      |                               ^
Main.cpp: In function 'int main()':
Main.cpp:181:9: error: 'cin' was not declared in this scope
  181 |         cin >> N;
      |         ^~~
Main.cpp:182:9: error: 'allZero' was not declared in this scope
  182 |         allZero=string(N,'0');
      |         ^~~~~~~
Main.cpp:182:17: error: 'string' was not declared in this scope
  182 |         allZero=string(N,'0');
      |                 ^~~~~~
Main.cpp:183:9: error: 'vector' was not declared in this scope
  183 |         vector<int> pickedRow(N,-1),pickedCol(N,-1);
      |         ^~~~~~
Main.cpp:183:16: error: expected primary-expression before 'int'
  183 |         vector<int> pickedRow(N,-1),pickedCol(N,-1);
      |                ^~~
Main.cpp:187:23: error: expected ';' before 'choice'
  187 |                 string choice(N,'0');
      |                       ^~~~~~~
      |                       ;
Main.cpp:191:28: error: 'pickedCol' was not declared in this scope
  191 |                         if(pickedCol[j]==-1)
      |                            ^~~~~~~~~
Main.cpp:193:33: error: 'choice' was not declared in this scope
  193 |                                 choice[j]='1';
      |                                 ^~~~~~
Main.cpp:196:38: error: 'pickedCol' was not declared in this scope
  196 |                 try_print_picked_col(pickedCol);
      |                                      ^~~~~~~~~
Main.cpp:196:17: error: 'try_print_picked_col' was not declared in this scope
  196 |                 try_print_picked_col(pickedCol);
      |                 ^~~~~~~~~~~~~~~~~~~~
Main.cpp:200:33: error: 'choice' was not declared in this scope
  200 |                         int col=choice.find('1');
      |                                 ^~~~~~
Main.cpp:201:25: error: 'assert' was not declared in this scope
  201 |                         assert(knownCol!=-1);
      |                         ^~~~~~
Main.cpp:201:25: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
Main.cpp:209:33: error: 'pickedRow' was not declared in this scope
  209 |                                 pickedRow[i]=col;
      |                                 ^~~~~~~~~
Main.cpp:214:31: error: expected ';' before 'prevChoice'
  214 |                         string prevChoice=choice;
      |                               ^~~~~~~~~~~
      |                               ;
Main.cpp:215:49: error: 'choice' was not declared in this scope
  215 |                         int litCells=test_row(i,choice);
      |                                                 ^~~~~~
Main.cpp:225:64: error: 'prevChoice' was not declared in this scope
  225 |                                 int curCnt=cut_half(cnt,choice,prevChoice);
      |                                                                ^~~~~~~~~~
Main.cpp:229:111: error: 'pickedRow' was not declared in this scope
  229 |                                         if((i==0 && test_horizontal(i,col)) || (i>0 && test_horizontal2(i,col,pickedRow[0])))
      |                                                                                                               ^~~~~~~~~
Main.cpp:238:73: error: 'assert' was not declared in this scope
  238 |                                                                         assert(!test_horizontal(i,j));
      |                                                                         ^~~~~~
Main.cpp:238:73: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
Main.cpp:256:49: error: 'pickedRow' was not declared in this scope
  256 |                                                 pickedRow[i]=choice.find('1');
      |                                                 ^~~~~~~~~
Main.cpp:275:33: error: 'pickedRow' was not declared in this scope
  275 |                                 pickedRow[i]=prevChoice.find('1');
      |                                 ^~~~~~~~~
Main.cpp:275:46: error: 'prevChoice' was not declared in this scope
  275 |                                 pickedRow[i]=prevChoice.find('1');
      |                                              ^~~~~~~~~~
Main.cpp:277:40: error: 'pickedRow' was not declared in this scope
  277 |                                 assert(pickedRow[i]!=-1);
      |                                        ^~~~~~~~~
Main.cpp:277:33: error: 'assert' was not declared in this scope
  277 |                                 assert(pickedRow[i]!=-1);
      |                                 ^~~~~~
Main.cpp:277:33: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
Main.cpp:280:26: error: 'pickedRow' was not declared in this scope
  280 |         print_picked_row(pickedRow);
      |                          ^~~~~~~~~
Main.cpp:280:9: error: 'print_picked_row' was not declared in this scope
  280 |         print_picked_row(pickedRow);
      |         ^~~~~~~~~~~~~~~~
Main.cpp: In function 'bool test_horizontal(int, int)':
Main.cpp:59:1: warning: control reaches end of non-void function [-Wreturn-type]
   59 | }
      | ^