Submission #306569

#TimeUsernameProblemLanguageResultExecution timeMemory
306569peti1234Painting Squares (IOI20_squares)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "squares.h" using namespace std; const int c=512; int n; vector<int> sol, s, ans, sz[c]; bool v[c][2]; void dfs(int a) { if (!v[a][0]) { v[a][0]=1, dfs(sz[a][0]); s.push_back(0); } if (!v[a][1]) { v[a][1]=1, dfs(sz[a][1]); s.push_back(1); } } vector<int> paint(int N) { n=N; for (int i=0; i<c; i++) sz[i].clear(), sol.clear(), s.clear(), ans.clear(), v[i][0]=0, v[i][1]=0; for (int i=0; i<c; i++) { int x=2*i%c; sz[i].push_back(x), sz[i].push_back(x+1); } dfs(0); for (int i=0; i<9; i++) sol.push_back(0); while(s.size()>0) sol.push_back(s.back()), s.pop_back(); for (int i=0; i<n; i++) ans.push_back(sol[i]); ans.push_back(min(10, n)); for (int i=0; i<10; i++) sol.push_back(-1); for (int i=n; i<n+10; i++) sol[i]=-1; return ans; } int find_location(int n, vector<int> sz) { int k=sz.size(); for (int i=0; i<c; i++) sz[i].clear(), sol.clear(), s.clear(), ans.clear(), v[i][0]=0, v[i][1]=0; for (int i=0; i<c; i++) { int x=2*i%c; sz[i].push_back(x), sz[i].push_back(x+1); } dfs(0); for (int i=0; i<9; i++) sol.push_back(0); while(s.size()>0) sol.push_back(s.back()), s.pop_back(); for (int i=0; i<n; i++) ans.push_back(sol[i]); ans.push_back(min(10, n)); for (int i=0; i<10; i++) sol.push_back(-1); for (int i=n; i<n+10; i++) sol[i]=-1; for (int i=0; i<n; i++) { bool jo=1; for (int j=0; j<k; j++) { if (sol[i+j]!=sz[j]) jo=0; } if (jo) return i; } return n; } int b1, b2, b3, w; vector<int> v1, v2; int main() { cin >> w; while(w--) { cin >> b1; v1=paint(b1); for (int i=0; i<v1.size(); i++) cout << v1[i] << " "; b3=v1.back(); cout << "\n"; cin >> b2; for (int i=0; i<b2; i++) { v2.clear(); for (int i=0; i<b3; i++) { int x; cin >> x; v2.push_back(x); } cout << find_location(b1, v2) << "\n"; } } return 0; }

Compilation message (stderr)

squares.cpp: In function 'int find_location(int, std::vector<int>)':
squares.cpp:36:35: error: request for member 'clear' in 'sz.std::vector<int>::operator[](((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   36 |     for (int i=0; i<c; i++) sz[i].clear(), sol.clear(), s.clear(), ans.clear(), v[i][0]=0, v[i][1]=0;
      |                                   ^~~~~
squares.cpp:39:15: error: request for member 'push_back' in 'sz.std::vector<int>::operator[](((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   39 |         sz[i].push_back(x), sz[i].push_back(x+1);
      |               ^~~~~~~~~
squares.cpp:39:35: error: request for member 'push_back' in 'sz.std::vector<int>::operator[](((std::vector<int>::size_type)i))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   39 |         sz[i].push_back(x), sz[i].push_back(x+1);
      |                                   ^~~~~~~~~
squares.cpp: In function 'int main()':
squares.cpp:65:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int i=0; i<v1.size(); i++) cout << v1[i] << " ";
      |                       ~^~~~~~~~~~