답안 #597640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597640 2022-07-16T13:01:26 Z cfalas 벽 칠하기 (APIO20_paint) C++17
0 / 100
2 ms 468 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<int, vector<int>> f;
struct seg{
	set<int> val;
	seg *L, *R;

	set<int> merge(set<int> &a, int as, set<int> &b){
		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);
		}
	}

	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 set<int>();
		else{
			set<int> sl = L->query(rl,rr,l,MID);
			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;
			}
			return merge(sl, MID-rl+1, sr);
		}
	}

	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();
	set<int> ok;
	unordered_set<int> poss;
	FOR(j,N-M+1){
		set<int> cc = s.query(j, j+M-1);
		/*
		cout<<j<<" "<<j+M-1<<": ";
		FOA(v, cc) cout<<v<<" ";
		cout<<endl;*/
		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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 1 ms 424 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Incorrect 1 ms 468 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 1 ms 424 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Incorrect 1 ms 468 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 1 ms 424 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Incorrect 1 ms 468 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 1 ms 424 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Incorrect 1 ms 468 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 428 KB Output is correct
8 Correct 1 ms 424 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Incorrect 1 ms 468 KB Output isn't correct
14 Halted 0 ms 0 KB -