Submission #1245570

#TimeUsernameProblemLanguageResultExecution timeMemory
1245570quannnguyen2009Painting Walls (APIO20_paint)C++20
100 / 100
413 ms12896 KiB
#include "paint.h" #include<bits/stdc++.h> #define fi first #define se second #define pb push_back #define ii pair<int, int> #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() using namespace std; const int N = 1e5+5, K = 1e5+5, mod = 1e9+7, inf = 1e18; int mx[N][2]; vector<int> lst[K]; vector<int> vec[2]; bool bl[N]; int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b) { for (int i=0; i<m; i++) { for (int j=0; j<a[i]; j++) lst[b[i][j]].pb(i); } for (int i=0; i<n; i++) { int id = i&1; while (sz(vec[id])) { mx[vec[id].back()][id] = 0; vec[id].pop_back(); } for (int j=0; j<sz(lst[c[i]]); j++) { mx[lst[c[i]][j]][id] = mx[(lst[c[i]][j]-1+m)%m][id^1]+1; if (mx[lst[c[i]][j]][id]>=m) bl[i] = 1; vec[id].pb(lst[c[i]][j]); } } for (int i=0; i<n; i++) { for (int j=0; j<sz(lst[c[i]]); j++) { mx[lst[c[i]][j]][i&1] = mx[(lst[c[i]][j]-1+m)%m][(i-1+n)%n]+1; if (mx[lst[c[i]][j]][i]>=m) bl[i] = 1; } } int ans = 0, idx = 0; while (idx<n) { bool ok = 0; for (int i=min(n, idx+m)-1; i>=idx; i--) { if (bl[i]) { ok = 1; idx = i+1; break; } } if (!ok) return -1; ans++; } return ans; }

Compilation message (stderr)

paint.cpp:11:52: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   11 | const int N = 1e5+5, K = 1e5+5, mod = 1e9+7, inf = 1e18;
      |                                                    ^~~~
#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...