제출 #399319

#제출 시각아이디문제언어결과실행 시간메모리
399319Collypso벽 칠하기 (APIO20_paint)C++17
0 / 100
1580 ms204 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int) (x).size() #define print(x) cout << x << endl #pragma GCC optimize ("O3") #pragma GCC optimize ("O2") //#define endl '\n' //#define int long long using namespace std; int subtask1(int N, int M, int K, vt<int> C, vt<int> A, vt<vt<int>> B) { map<int, int> MP; for(int i = 0; i < M; i++) { for(int x : B[i]) { MP[x] = i + 1; } } int i, j, ans; i = j = ans = 0; while(i <= N - M) { if (MP[C[i]] == 0) return -1; j = i + 1; while(j < N) { if (MP[C[j]] - 1 != MP[C[j - 1]] % M) break; j++; } j--; if (j - i + 1 < M) return -1; ans += (j - i + M) / M; i = j + 1; } if (i != N) return -1; return ans; } int minimumInstructions(int N, int M, int K, vt<int> C, vt<int> A, vt<vt<int>> B) { bool sub1 = 1; for(int i = 0; i < M; i++) { if (A[i] != 1) { sub1 = 0; break; } } if (sub1) return subtask1(N, M, K, C, A, B); vt<int> dp(N); int i = 0; while(i <= N - M) { if (i > 0 && !dp[i - 1]) continue; for(int master = 0; master < M; master++) { int m = master; int j = i; while(j < N) { int tmp = lower_bound(all(B[m]), C[j]) - B[m].begin(); if (B[m][tmp] != C[j]) break; m = (m + 1) % M; j++; } if (j - i + 1 < M) continue; int tmp = i > 0 ? dp[i - 1] : 0; dp[j] = !dp[j] ? (i + j + m) / M + tmp : min(dp[j], (i + j + m) / M + tmp); } i++; } if (dp[N - 1]) return dp[N - 1]; return -1; } /** main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int ans = minimumInstructions(6, 4, 4, {2, 1, 0, 3, 2, 1}, {3}, {{2}, {1}, {0}, {3}}); print(ans); } /**/

컴파일 시 표준 에러 (stderr) 메시지

paint.cpp:99:1: warning: "/*" within comment [-Wcomment]
   99 | /**/
      |
#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...