이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "paint.h"
#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma target("avx2")
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll
const int MAX=1e5+15;
const int B=300;
const int N=104;
const int block=400;
const int maxB=MAX/B+10;
const ll inf=2e9;
const int mod=998244353;
const int mod1=1e9+9;
const ld eps=1e-9;
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int good[MAX];
int cnt[MAX];
int n,m;
vector<int> c;
vector<int> g[MAX],G[MAX];
int f;
void add(int i){
for(int x:g[i]){
cnt[x]++;
if(cnt[x]==m)f++;
// cout<<i<<" "<<x<<"\n";
}
}
void del(int i){
for(int x:g[i]){
if(cnt[x]==m)f--;
cnt[x]--;
}
}
int dp[MAX];
struct segtree{
int t[4*MAX];
void build(int v,int tl,int tr){
t[v]=inf;
if(tl==tr){
return;
}
int tm=(tl+tr)/2;
build(2*v,tl,tm);
build(2*v+1,tm+1,tr);
}
void update(int v,int tl,int tr,int pos,int x){
if(tl==tr){
t[v]=x;
return;
}
int tm=(tl+tr)/2;
if(pos<=tm)update(2*v,tl,tm,pos,x);
else update(2*v+1,tm+1,tr,pos,x);
t[v]=min(t[2*v],t[2*v+1]);
}
int get(int v,int tl,int tr,int l,int r){
if(l>r||tl>r||l>tr)return inf;
if(l<=tl&&tr<=r)return t[v];
int tm=(tl+tr)/2;
return min(get(2*v,tl,tm,l,r),get(2*v+1,tm+1,tr,l,r));
}
}t;
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B) {
n=N;
m=M;
c=C;
// cerr<<"OK\n";
for(int i=0;i<M;i++){
for(int x:B[i]){
G[x].pb(i);
}
}
for(int i=0;i<N;i++){
g[i]=G[C[i]];
// cout<<"!!! "<<i<<"\n";
for(int j=0;j<sz(g[i]);j++){
g[i][j]-=i;
while(g[i][j]<0)g[i][j]+=M;
// cout<<g[i][j]<<" ";
}
// cout<<"\n";
}
for(int i=0;i<M;i++)add(i);
if(f)good[M-1]=1;
// cout<<good[M-1]<<"\n";
// return -1;
for(int i=M;i<N;i++){
del(i-M);
add(i);
if(f)good[i]=1;
// cout<<i<<" "<<good[i]<<"\n";
}
if(!good[M-1])return -1;
t.build(1,0,N-1);
// for(int i=0;i<N;i++){
// cout<<t.get(1,0,N-1,i,i)<<"\n";
// }
t.update(1,0,N-1,M-1,1);
for(int i=M;i<N;i++){
if(good[i]){
t.update(1,0,N-1,i,t.get(1,0,N-1,i-M,i-1)+1);
}
}
return (t.get(1,0,N-1,N-1,N-1)==inf?-1:t.get(1,0,N-1,N-1,N-1));
}
컴파일 시 표준 에러 (stderr) 메시지
paint.cpp:4: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
4 | #pragma optimize("Ofast")
|
paint.cpp:5: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
5 | #pragma target("avx2")
|
# | 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... |