이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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()
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
//#define endl '\n'
//#define int long long
using namespace std;
bool exists(vt<int>& master, int m)
{
return upper_bound(all(master), m) - lower_bound(all(master), m);
}
int minimumInstructions(int N, int M, int K, vt<int> C, vt<int> A, vt<vt<int>> B)
{
vt<int> dp(N, INT_MAX);
vt<vt<int>> master(K);
for(int i = 0; i < M; i++)
for(int j = 0; j < A[i]; j++) master[B[i][j]].pb(i);
for(int i = 0; i <= N - M; i++)
{
if (i > 0 && dp[i] == INT_MAX && dp[i - 1] == INT_MAX) continue;
for(int m : master[C[i]])
{
int l = 0;
while(l < M && exists(master[C[i + l]], (m + l) % M)) l++;
if (l != M) continue;
int tmp = (i > 0 && (dp[i - 1] != INT_MAX)) ? dp[i - 1] + 1 : 1;
for(l = 0; l < M; l++) dp[i + l] = min(dp[i + l], tmp);
}
}
if (dp[N - 1] == INT_MAX) return -1;
return dp[N - 1];
}
/**
main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
freopen("input.txt", "r", stdin);
int N, M, K;
cin >> N >> M >> K;
vt<int> C(N), A(M);
vt<vt<int>> B(M);
for(int i = 0; i < N; i++) cin >> C[i];
for(int i = 0; i < M; i++)
{
cin >> A[i];
B[i].resize(A[i]);
for(int j = 0; j < A[i]; j++) cin >> B[i][j];
}
//cout << M << endl;
int ans = minimumInstructions(N, M, K, C, A, B);
cout << ans << endl;
//int ans = minimumInstructions(6, 4, 4, {2, 1, 0, 3, 2, 1}, {3}, {{2}, {1}, {0}, {3}});
//cout << ans << endl;
}
/**/
컴파일 시 표준 에러 (stderr) 메시지
paint.cpp:66:1: warning: "/*" within comment [-Wcomment]
66 | /**/
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |