Submission #697501

#TimeUsernameProblemLanguageResultExecution timeMemory
697501sharaelongPainting Walls (APIO20_paint)C++17
63 / 100
1600 ms266796 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N = 1e5 + 1; int minimumInstructions(int n, int m, int k, vector<int> C, vector<int> A, vector<vector<int>> B) { vector<vector<int>> likes(k); for (int i=0; i<m; ++i) { for (int j=0; j<A[i]; ++j) { likes[B[i][j]].push_back(i); } } // for (int i=0; i<k; ++i) { // for (int x: likes[i]) cout << x << ' '; // cout << endl; // } vector<vector<int>> nxt(n); vector<vector<bool>> processed(n); for (int i=0; i<n; ++i) { nxt[i].resize(likes[C[i]].size(), -1); processed[i].resize(likes[C[i]].size(), false); } vector<int> pnt(n, 0); for (int i=0; i+1<n; ++i) { const vector<int>& cands = likes[C[i+1]]; for (int j=0; j<likes[C[i]].size(); ++j) { int x = likes[C[i]][j]; if (x+1 < m) { while (pnt[i+1] < cands.size() && cands[pnt[i+1]] <= x) pnt[i+1]++; if (pnt[i+1] < cands.size() && cands[pnt[i+1]] == x+1) nxt[i][j] = pnt[i+1]; } else { if (!cands.empty() && cands[0] == 0) nxt[i][j] = 0; } } } // for (int i=0; i<n; ++i) { // for (int x: nxt[i]) cout << x << ' '; // cout << endl; // } vector<int> okay(n+1, 0); for (int i=0; i<n; ++i) { for (int j=0; j<likes[C[i]].size(); ++j) { if (!processed[i][j]) { processed[i][j] = true; int ii = i, jj = j; while (ii < n && nxt[ii][jj] != -1) { jj = nxt[ii][jj]; ii++; processed[ii][jj] = true; } if (ii == n) ii--; if (ii-i+1 >= m) { okay[i]++; okay[ii-m+2]--; } } } } for (int i=1; i<okay.size(); ++i) okay[i] += okay[i-1]; // for (int i=0; i<n; ++i) cout << okay[i] << ' '; // cout << endl; vector<int> valid_pos; for (int i=0; i<n; ++i) { if (okay[i] > 0) valid_pos.push_back(i); } if (valid_pos.empty() || valid_pos[0] > 0) return -1; int ans = 1; int curr = 0; while (curr + m < n) { auto it = upper_bound(valid_pos.begin(), valid_pos.end(), curr+m); if (*prev(it) == curr) return -1; curr = *prev(it); ans++; } return ans; }

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:30:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int j=0; j<likes[C[i]].size(); ++j) {
      |                       ~^~~~~~~~~~~~~~~~~~~
paint.cpp:33:33: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |                 while (pnt[i+1] < cands.size() && cands[pnt[i+1]] <= x) pnt[i+1]++;
paint.cpp:34:30: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |                 if (pnt[i+1] < cands.size() && cands[pnt[i+1]] == x+1) nxt[i][j] = pnt[i+1];
paint.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int j=0; j<likes[C[i]].size(); ++j) {
      |                       ~^~~~~~~~~~~~~~~~~~~
paint.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for (int i=1; i<okay.size(); ++i) okay[i] += okay[i-1];
      |                   ~^~~~~~~~~~~~
#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...