답안 #597670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597670 2022-07-16T14:06:02 Z cfalas 벽 칠하기 (APIO20_paint) C++17
0 / 100
0 ms 212 KB
#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<set<int>, int> mm;
vector<set<int> > mmr(1, set<int>());
int sc=1;

struct myset{
	set<int> val;

	void insert(int x){
		val.insert(x);
		if(mm.count(val)==0){
			mmr.push_back(val);
			mm[val] = sc++;
		}
	}

	int i(){
		return mm[val];
	}

	myset(int x){
		val = mmr[x];
		if(mm.count(val)==0){
			mmr.push_back(val);
			mm[val] = sc++;
		}
	}
	myset(set<int> v){
		val = v;
	}
	myset(){}
};

map<int, vector<int>> f;
struct seg{
	int val;
	seg *L, *R;

	int merge(int a, int as, int b){
		myset ans;
		myset aa=myset(a), bb=myset(b);
		FOA(v,aa.val){
			if(bb.val.count((v + as)%M)) ans.insert(v);
		}
		return ans.i();
	}

	void build(int l=0, int r=N-1){
		if(l==r){
			set<int> cc;
			FOA(v, f[c[l]]){
				cc.insert(v);
			}
			val = myset(cc).i();
		}
		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);
		}
	}

	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 0;
		else{
			int sl = L->query(rl,rr,l,MID);
			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<<": ";
			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) {
	mm[{}] = 0;
	M = m;
	N = n;
	c = C;
	FOR(i,M){
		FOA(v, B[i]){
			f[v].push_back(i);
		}
	}
	seg s;
	s.build();
	//s.print();
	set<int> ok;
	FOR(j,N-M+1){
		int cc = s.query(j, j+M-1);
		if(cc!=0){
			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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -