Submission #710728

#TimeUsernameProblemLanguageResultExecution timeMemory
710728Ronin13Crossing (JOI21_crossing)C++14
26 / 100
1059 ms8160 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int nmax = 1000001; map <vector <int>, bool> used; vector <vector <int> > vec; vector <int> op(vector <int> &a, vector <int> &b){ vector <int> ans; for(int i = 0; i < a.size(); i++){ int x = a[i] + b[i]; x = -x; x %= 3; x += 3; x %= 3; ans.pb(x); } return ans; } void rec(vector <int> &v){ used[v] = true; vec.pb(v); vector <vector <int> > q; for(auto to : vec){ vector <int> x = op(to, v); if(used[x]) continue; q.push_back(x); used[x] = true; } for(auto to : q) rec(to); } int L[nmax], R[nmax]; int blsize = 501; bool good[nmax][10]; int val[nmax]; int opt[nmax][10]; vector <int> b; void update_block(int ind, int v, int bl){ if(opt[bl][ind] == v) good[bl][ind] = true; else good[bl][ind] = false; val[bl] = v; } void fil(int bl){ if(val[bl] == -1) return; for(int i = L[bl]; i <= R[bl]; i++) b[i] = val[bl]; val[bl] = -1; } bool check(int bl, int ind){ for(int i = L[bl]; i <= R[bl]; i++){ if(b[i] != vec[ind][i]) return false; } return true; } void update_ran(int ind, int l, int r, int v){ int bl = l / blsize; good[bl][ind] = false; fil(bl); for(int i = l; i <= r; i++) b[i] = v; good[bl][ind] = check(bl, ind); } bool CH(int sz){ bool ans = false; for(int j = 0; j < vec.size(); j++){ bool cur = true; for(int i= 0; i <= sz; i++){ cur &= good[i][j]; } ans |= cur; } return ans; } int main(){ // ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int cur = 0; int curbl = 0; L[0] = 0; for(int i = 1; i < n; i++){ if(cur + 1 > blsize){ R[curbl] = i - 1; cur = 1; L[++curbl] = i; } else cur++; } R[curbl] = n - 1; for(int i = 0; i <= curbl ;i++) val[i] = -1; string a[3]; for(int i = 0; i < 3; i++){ vector<int> v; cin >> a[i]; for(int j = 0; j < n; j++){ if(a[i][j] == 'O') v.pb(0); if(a[i][j] == 'J') v.pb(1); if(a[i][j] == 'I') v.pb(2); } //used[v] = true; rec(v); //vec.pb(v); } // cout << vec.size() << "\n"; int q; cin >> q; for(int i = 0; i < n; i++){ char c; cin >> c; if(c == 'J') b.pb(1); if(c == 'O') b.pb(0); if(c == 'I') b.pb(2); } // cout << vec.size(); for(int i = 0; i < n; i++){ for(int j = 0; j < vec.size(); j++) update_ran(j, i, i, b[i]); } for(int j = 0; j < vec.size(); j++){ for(int i = 0; i <= curbl; i++){ opt[i][j] = vec[j][L[i]]; for(int x = L[i] + 1; x <= R[i]; x++) if(vec[j][x] != vec[j][x - 1]) opt[i][j] = -1; } } CH(curbl) ? cout << "Yes\n" : cout << "No\n"; while(q--){ int l,r; cin >> l >> r; char c; cin >> c; int x; if(c == 'O') x = 0; if(c == 'J') x = 1; if(c == 'I') x = 2; l--, r--; int X = l / blsize; int Y = r / blsize; if(X == Y){ for(int j = 0; j < vec.size(); j++) update_ran(j, l, r, x); } else{ for(int i = X + 1; i < Y; i++){ for(int j = 0; j < vec.size(); j++) update_block(j, x, i); } for(int j = 0; j < vec.size(); j++){ update_ran(j, l, R[X], x); update_ran(j, L[Y], r, x); } } CH(curbl) ? cout << "Yes\n" : cout << "No\n"; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'std::vector<int> op(std::vector<int>&, std::vector<int>&)':
Main.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
Main.cpp: In function 'bool CH(int)':
Main.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(int j = 0; j < vec.size(); j++){
      |                    ~~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:141:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |         for(int j = 0; j < vec.size(); j++)
      |                        ~~^~~~~~~~~~~~
Main.cpp:144:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |     for(int j = 0; j < vec.size(); j++){
      |                    ~~^~~~~~~~~~~~
Main.cpp:167:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |             for(int j = 0; j < vec.size(); j++)
      |                            ~~^~~~~~~~~~~~
Main.cpp:172:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |                 for(int j = 0; j < vec.size(); j++)
      |                                ~~^~~~~~~~~~~~
Main.cpp:175:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  175 |             for(int j = 0; j < vec.size(); j++){
      |                            ~~^~~~~~~~~~~~
Main.cpp:53:5: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |     if(opt[bl][ind] == v)
      |     ^~
Main.cpp:156:13: note: 'x' was declared here
  156 |         int x;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...