Submission #414326

#TimeUsernameProblemLanguageResultExecution timeMemory
414326ACmachinePainting Walls (APIO20_paint)C++17
51 / 100
1587 ms67196 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){ for(int x : starts[i]){ cout << x << " "; } cout << endl; } */ REP(i, m){ deque<int> dq; // if max - min == m - 1; ok if(starts[i].size() < m) continue; REP(j, m){ dq.push_back(starts[i][j]); if(dq.back() - dq[0] == m - 1){ starts_valid[dq[0]] = true; } } FOR(j, m, starts[i].size(), 1){ dq.pop_front(); dq.push_back(starts[i][j]); if(dq.back() - dq[0] == m - 1){ starts_valid[dq[0]] = true; } } } /* for(int x : starts_valid){ cout << x << " "; } cout << endl; */ // I have all valid starts vector<int> dp(n + 1, INF); dp[0] = 0; FOR(i, m, n + 1, 1){ if(!starts_valid[i - m]) continue; FOR(j,i - m, i, 1){ dp[i] = min(dp[i], dp[j] + 1); } } /* for(int x : dp){ cout << x << " "; } cout << endl; */ 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:44:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |         if(starts[i].size() < m)
      |            ~~~~~~~~~~~~~~~~~^~~
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:52:9: note: in expansion of macro 'FOR'
   52 |         FOR(j, m, 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...