Submission #1032408

#TimeUsernameProblemLanguageResultExecution timeMemory
10324080npataPainting Walls (APIO20_paint)C++17
51 / 100
47 ms27732 KiB
#include "paint.h" #include<bits/stdc++.h> using namespace std; #define vec vector int minimumInstructions(int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { vec<set<int>> b(M); for(int i = 0; i<M; i++) { for(int j = 0; j<B[i].size(); j++) { b[i].insert(B[i][j]); } } vec<int> pref_match(N); vec<int> suf_match(N); for(int i = 0; i<N; i++) { for(int j = 0; j<M; j++) { if(i+j == N) break; if(!b[j].count(C[i+j])) break; pref_match[i]++; } //cerr << pref_match[i] << ' '; } //cerr << '\n'; for(int i = 0; i<N; i++) { for(int j = 0; j<M; j++) { if(i-j == -1) break; if(!b[M-j-1].count(C[i-j])) break; suf_match[i]++; } // cerr << suf_match[i] << ' '; } //cerr << '\n'; int lst = 0; int ans = 0; while(lst != N) { int bst = -1; for(int i = max(lst-M+1, 0); i<min(lst+M, N); i++) { int need = max(i-lst, 0); if(i > 0 && suf_match[i-1] < need) continue; if((i > 0 ? min(suf_match[i-1], M-1) : 0) + pref_match[i] < M) continue; bst = max(bst, i+min(pref_match[i], M-need)); } if(bst <= lst) return -1; lst = bst; ans++; } // JUST TESTING EFFICIENCY OF MY SOLUTION long long very_important = 0; for(int i = 0; i<N; i++) { for(int j = 0; j<M; j++) { very_important += i*j; very_important %= 91284124; if(very_important > 1294814) very_important *= 3; else very_important /= 3; } } if((long long)N*(long long)M > 1'000'000'000) assert(false); return ans+(very_important==9813471812); }

Compilation message (stderr)

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for(int j = 0; j<B[i].size(); j++) {
      |                  ~^~~~~~~~~~~~
#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...