Submission #569792

#TimeUsernameProblemLanguageResultExecution timeMemory
569792aryan12Painting Walls (APIO20_paint)C++17
28 / 100
1594 ms164176 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; int minimumInstructions(int N, int M, int K, vector<int> colors, vector<int> num, vector<vector<int> > likes) { vector<vector<int> > dp(N, vector<int> (M, -1e9)); set<int> likings[M]; for(int contractor = 0; contractor < M; contractor++) { for(int j = 0; j < num[contractor]; j++) { likings[contractor].insert(likes[contractor][j]); } } for(int i = N - 1; i >= 0; i--) { for(int j = 0; j < M; j++) { if(likings[j].count(colors[i])) { if(i == N - 1 || dp[i + 1][(j + 1) % M] == -1e9) { dp[i][j] = 1; } else { dp[i][j] = dp[i + 1][(j + 1) % M] + 1; } } // cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << "\n"; } // cout << "\n\n\n\n"; } vector<int> start_pos; for(int i = N - M; i >= 0; i--) { for(int j = 0; j < M; j++) { if(dp[i][j] >= M) { start_pos.push_back(i); // cout << i << "\n"; break; } } } int ans = 0; int min_x = N; for(int i = 0; i < start_pos.size(); i++) { // cout << "start_pos[i] = " << start_pos[i] << ", M = " << M << ", minx = " << min_x << "\n"; if(start_pos[i] + M - 1 < min_x - 1) { return -1; } if(i == start_pos.size() - 1 || start_pos[i + 1] + M - 1 < min_x - 1 || start_pos[i] == 0) { min_x = start_pos[i]; ans++; } } if(min_x != 0) return -1; 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:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0; i < start_pos.size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~~~
paint.cpp:57:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         if(i == start_pos.size() - 1 || start_pos[i + 1] + M - 1 < min_x - 1 || start_pos[i] == 0)
      |            ~~^~~~~~~~~~~~~~~~~~~~~~~
#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...