Submission #414338

#TimeUsernameProblemLanguageResultExecution timeMemory
414338ACmachinePainting Walls (APIO20_paint)C++17
100 / 100
1209 ms260992 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l)) #define FORD(i, j, k, l) for(int i = (j); i>=(k); i -= (l)) #define REP(i, n) FOR(i, 0, n, 1) #define REPD(i, n) FORD(i, n, 0, 1) #define pb push_back typedef long long ll; const int INF = (int)1e9; const ll INFF = (ll)1e18; int minimumInstructions( int n, int m, int k, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { vector<vector<int>> g(k); // which contractors like this color REP(i, m){ for(int x : B[i]){ g[x].pb(i); // color x is liked by ith contractor too } } vector<vector<int>> starts(m); // for this start as modulo, which ones are okay? vector<bool> starts_valid(n, false); // does valid segment start here? REP(i, n){ for(int off : g[C[i]]){ int start = (off - i); start %= m; if(start < 0) start += m; starts[start].pb(i); } } REP(i, m){ // if max - min == m - 1; ok FOR(j, m - 1, starts[i].size(), 1){ if(starts[i][j] - starts[i][j - (m - 1)] == m - 1) starts_valid[starts[i][j - (m - 1)]] = true; } } // I have all valid starts vector<int> dp(n + 1, INF); multiset<int> se; se.insert(0); se.insert(INF + 12); // this last one will not be erased dp[0] = 0; FOR(i, m, n + 1, 1){ if(!starts_valid[i - m]){ if(se.find(dp[i - m]) != se.end()) se.erase(se.find(dp[i - m])); se.insert(dp[i]); continue; } /* FOR(j,i - m, i, 1){ dp[i] = min(dp[i], dp[j] + 1); } */ dp[i] = *se.begin() + 1; if(se.find(dp[i - m]) != se.end()) se.erase(se.find(dp[i - m])); se.insert(dp[i]); } if(dp[n] >= INF){ return -1; } else{ return dp[n]; } return 0; }

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:6:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
      |                                            ^
paint.cpp:36:9: note: in expansion of macro 'FOR'
   36 |         FOR(j, m - 1, starts[i].size(), 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...