이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#include "paint.h"
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
int M, N;
vi c;
map<int, vector<int>> f;
struct seg{
unordered_set<int> val;
seg *L, *R;
unordered_set<int> merge(unordered_set<int> &a, int as, unordered_set<int> &b){
unordered_set<int> ans;
FOA(v,a){
if(b.count((v + as)%M)) ans.insert(v);
}
return ans;
}
void build(int l=0, int r=N-1){
if(l==r){
FOA(v, f[c[l]]){
val.insert(v);
}
}
else{
L = new seg;
R = new seg;
L->build(l,MID);
R->build(MID+1,r);
val = merge(L->val, MID-l+1, R->val);
}
}
unordered_set<int> query(int rl, int rr, int l=0, int r=N-1){
if(rl<=l && r<=rr) return val;
else if(rr<l || r<rl) return unordered_set<int>();
else{
unordered_set<int> sl = L->query(rl,rr,l,MID);
unordered_set<int> sr = R->query(rl,rr,MID+1,r);
if(rr<=MID){
/*
cout<<"Return left "<<l<<" "<<r<<": ";
FOA(v,sl) cout<<v<<" ";
cout<<endl;*/
return sl;
}
if(rl>MID){
/*
cout<<"Return right "<<l<<" "<<r<<": ";
FOA(v,sr) cout<<v<<" ";
cout<<endl;*/
return sr;
}
//cout<<"merge "<<l<<" "<<r<<": ";
unordered_set<int> qq;
if(l<=rl) qq = merge(sl, MID-rl+1, sr);
else qq = merge(sl, MID-l+1, sr);
/*
FOA(v, sl) cout<<v<<" ";
cout<<" | ";
FOA(v, sr) cout<<v<<" ";
cout<<" | ";
FOA(v, qq) cout<<v<<" ";
cout<<endl;*/
return qq;
}
}
void print(int l=0, int r=N-1){
cout<<l<<" "<<r<<": ";
FOA(v, val) cout<<v<<" ";
cout<<endl;
if(l!=r){
L->print(l, MID);
R->print(MID+1,r);
}
}
};
int minimumInstructions(int n, int m, int K, std::vector<int> C,
vector<int> A, vector<std::vector<int>> B) {
M = m;
N = n;
c = C;
FOR(i,M){
FOA(v, B[i]){
f[v].push_back(i);
}
}
seg s;
s.build();
//s.print();
unordered_set<int> ok;
FOR(j,N-M+1){
unordered_set<int> cc = s.query(j, j+M-1);
/*cout<<j<<" "<<j+M-1<<": ";
FOA(v, cc) cout<<v<<" ";
cout<<endl;*/
/*
unordered_set<int> poss;
FOA(v, f[C[j]]) poss.insert(v);
FORi(i,1,M){
unordered_set<int> npos;
FOA(v, f[C[j+i]]){
int pp = (v-i + M)%M;
if(poss.count(pp)) npos.insert(pp);
}
poss = npos;
}
FOA(v, poss) cout<<v<<" ";
cout<<endl;
if(cc!=poss) return -1;*/
if(!cc.empty()){
ok.insert(j);
}
}
if(!ok.count(0)) return -1;
int p=0;
int cp=M;
int ans = 1;
while(cp<N){
//cout<<p<<" "<<cp<<endl;
while(!ok.count(cp)) cp--;
if(cp<=p) return -1;
p = cp;
cp+=M;
ans++;
}
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... |