Submission #736384

#TimeUsernameProblemLanguageResultExecution timeMemory
736384minhcoolPainting Walls (APIO20_paint)C++17
0 / 100
7 ms9716 KiB
#include "paint.h" #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 4e5 + 5; const int oo = 1e18 + 7, mod = 1e9 + 7; int n, m, k; int arr[N]; vector<int> like[N]; int total[N]; bool okay[N]; int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B){ n = N, m = M, k = K; for(int i = 0; i < n; i++) arr[i + 1] = C[i] + 1; for(int i = 0; i < m; i++){ for(auto it : B[i]) like[it + 1].pb(i + 1); } for(int i = 1; i <= k; i++) assert(like[i].size() <= 700); for(int i = 1; i <= m; i++){ for(auto it : like[arr[i]]){ int temp = (it - (i - 1) + 2 * m) % m; if(!temp) temp = m; total[temp]++; //okay[1] |= (total[temp] == m); } } int cnt = 0; for(int i = 1; i <= m; i++) cnt += (total[i] == m); okay[1] = (cnt != 0); int temp = (n / m) + 1; temp *= m; for(int i = m + 1; i <= n; i++){ for(auto it : like[arr[i - m]]){ int temp = (it - i + 1 + temp) % m; // cout << i << " " << temp << "\n"; if(!temp) temp = m; if(total[temp] == m) cnt--; //cnt[total[temp]]--; total[temp]--; //cnt[total[temp]]++; //total[temp]++; } for(auto it : like[arr[i]]){ int temp = (it - i + 1 + temp) % m; if(!temp) temp = m; //cnt[total[temp]]--; total[temp]++; if(total[temp] == m) cnt++; //cnt[total[temp]]++; } okay[i - m + 1] = (cnt != 0); } //for(int i = 1; i <= (n - m + 1); i++) cout << okay[i] << " "; //cout << "\n"; if(!okay[1]) return -1; vector<int> okays; for(int i = 1; i <= n - m + 1; i++) if(okay[i]) okays.pb(i); int ans = 1, itr = m; while(itr < n){ //cout << itr << "\n"; vector<int>::iterator it = lower_bound(okays.begin(), okays.end(), itr + 2); assert(it != okays.begin()); it--; int temp = ((*it) + m - 1); if(temp <= itr) return -1; itr = temp; ans++; } return ans; }

Compilation message (stderr)

paint.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:60:27: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |    int temp = (it - i + 1 + temp) % m;
      |               ~~~~~~~~~~~~^~~~~~~
paint.cpp:50:27: warning: 'temp' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |    int temp = (it - i + 1 + temp) % m;
      |               ~~~~~~~~~~~~^~~~~~~
#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...