Submission #553297

#TimeUsernameProblemLanguageResultExecution timeMemory
553297FatihSolakPainting Walls (APIO20_paint)C++17
0 / 100
2 ms2644 KiB
#include "paint.h" #include <bits/stdc++.h> #define N 100005 #define K 705 using namespace std; vector<int> col[N]; int dp[N][K]; int ok[N]; int minimumInstructions(int n, int m, int k, vector<int> c,vector<int> a, vector<vector<int>> b) { for(int i = 0;i<m;i++){ for(int j = 0;j<a[i];j++){ col[b[i][j]].push_back(i); } } /* for(int i = 0;i<k;i++){ for(auto u:col[i]){ cout << u << " "; } cout << endl; }*/ for(int i = 0;i<col[c[0]].size();i++){ dp[0][i] = 1; if(dp[0][i] == m) ok[0 - m + 1] = 1; } for(int i = 1;i<n;i++){ int pt = 0; for(int j = 0;j<col[c[i]].size();j++){ dp[i][j] = 1; while(pt + 1 < col[c[i-1]].size() && col[c[i-1]][pt] + 1 < col[c[i]][j]){ pt++; } //cout << "hey" << pt << endl; if(col[c[i-1]][pt] + 1 == col[c[i]][j]){ dp[i][j] = max(dp[i][j],min(m, dp[i-1][pt]+1)); } if(col[c[i]][j] == 0 && col[c[i-1]].back() == m-1){ dp[i][j] = max(dp[i][j],min(m, dp[i-1][col[c[i-1]].size()-1]+1)); } //cout << dp[i][j] << " "; if(dp[i][j] == m) ok[i - m +1] = 1; } //cout << endl; } /* for(int i = 0;i<n;i++){ cout << ok[i] << " "; } cout << endl;*/ int cnt = 0; int last = -1; int maxi = 0; while(maxi < n){ int val = maxi; for(int i = last+1;i<=maxi;i++){ if(ok[i]){ val = max(val,i + m); } } if(val == maxi){ return -1; } cnt++; last = maxi+1; maxi = val; } return cnt; }

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:22:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i = 0;i<col[c[0]].size();i++){
      |                ~^~~~~~~~~~~~~~~~~
paint.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int j = 0;j<col[c[i]].size();j++){
      |                 ~^~~~~~~~~~~~~~~~~
paint.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    while(pt + 1 < col[c[i-1]].size() &&  col[c[i-1]][pt] + 1 < col[c[i]][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...