Submission #1056268

#TimeUsernameProblemLanguageResultExecution timeMemory
1056268vjudge1Painting Walls (APIO20_paint)C++17
0 / 100
0 ms348 KiB
#include "paint.h" //Dost Seferoğlu #include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") using namespace std; //#define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define all(cont) cont.begin(),cont.end() #define vi vector<int> const int MOD = 1e9+7,inf = 2e9; const int N = 2e5; int minimumInstructions( int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { vector<int> f[K]; for (int i=0;i<M;i++) { for (int j=0;j<A[i];j++) { f[B[i][j]].push_back(i); } } vi go(N,0); go[N-1] = 1; vector<bool> cool(N,0); if (M == 1) cool[N-1] = true; vi lst(M,0); for (auto it : f[C[N-1]]) lst[it] = 1; for (int i=N-2;i>=0;i--) { go[i] = 1; vector<pii> ps; for (auto it : f[C[i]]) { auto iter = lower_bound(all(f[C[i+1]]),((it+1)%M)); if (iter != f[C[i+1]].end() && *iter == (it+1)%M) { go[i] = max(go[i],min(M,lst[*iter]+1)); ps.push_back({it,min(M,lst[*iter]+1)}); } else ps.push_back({it,1}); } for (auto it : ps) lst[it.ff] = it.ss; if (go[i] == M) cool[i] = true; } int ans = 0; int cover = 0; stack<int> cools; for (int i=0;i<N;i++) { if (cool[i]) cools.push(i); if (cover < i) { if (cools.empty() || cools.top()+M-1 < i) { ans = inf; break; } else { ans++; cover = cools.top()+M-1; cools.pop(); } } else continue; } return ((ans >= inf)?-1:ans); }
#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...