이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int minimumInstructions(int n, int m, int K, vector<int> C, vector<int> A, vector<vector<int>> B){
vector<vector<int>> has_color(K);
vector<unordered_map<int, int>> sth(n);
vector<vector<int>> liked_by(n);
for(int i = 0; i < n; i++) has_color[C[i]].pb(i);
for(int i = 0; i < m; i++) for(int x: B[i]) for(int y: has_color[x])
sth[y][i] = 1, liked_by[y].pb(i);
vector<bool> p(n, 0);
for(int i = n-2; i >= 0; i--){
for(int x: liked_by[i]){
if(sth[i+1].find((x+1)%m) != sth[i+1].end()) sth[i][x] = sth[i+1][(x+1)%m]+1;
}
}
for(int i = 0; i < n; i++) for(int x: liked_by[i]) if(sth[i][x] >= m) p[i] = 1;
int ans = 0, ls = -1, c = 0;
for(int i = n-1; i >= 0; i--){
c++;
if(p[i]) ls = i;
if(c == m || i == 0){
if(ls == -1) return -1;
ans++;
c=ls-i;
ls = -1;
}
}
return ans;
}
# | 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... |