답안 #1018104

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018104 2024-07-09T14:23:41 Z NintsiChkhaidze 최후의 만찬 (IOI12_supper) C++17
100 / 100
2348 ms 56904 KB
#include <bits/stdc++.h>
#include "advisor.h"
#define pb push_back
using namespace std;

const int MM = 2e6 + 5;

vector <int> st[MM];
bool onn[MM],val[MM],valk[MM];

void ComputeAdvice(int *C, int N, int K, int M) {
	int n=N,k=K;
	for (int i=N-1;i>=0;i--){
		st[C[i]].pb(i);
	}
	
	set <pair<int,int> > stt;
	for (int i=0;i<K;i++){
		onn[i] = 1;
		int val = 0;
		if (!st[i].size()) val=1e9;
		else val=st[i].back();
		stt.insert({val,i});
	}
	
	int i;
	vector <int> vec;
	for (i = 0; i < N; i++) {
    	int req = C[i];
    	if (onn[req]) {
    		vec.pb(-1);
    		int val = 0;
			if (!st[req].size()) val=1e9;
			else val=st[req].back();
			stt.erase(stt.find({val,req}));
			
			while (st[req].size() && st[req].back() <= i){
    			st[req].pop_back();
			}
			val = 0;
			if (!st[req].size()) val=1e9;
			else val=st[req].back();
			stt.insert({val,req});
			continue;
		}
    	
		int idx=(--stt.end())->second; stt.erase(--stt.end());
		vec.pb(idx);
		onn[idx] = 0;
		onn[req] = 1;
		
		while (st[req].size() && st[req].back() <= i){
    		st[req].pop_back();
		}
		
		int val = 0;
		if (!st[req].size()) val=1e9;
		else val=st[req].back();
		stt.insert({val,req});
  	}
  	
//  	cout<<"write "<<endl;
  	for (int i = 0; i < k; i++){
  		int x = i;
  		bool check = 0;
  		
  		for (int j = 0; j < n; j++){
  			if (C[j] == x) break;
			if (vec[j] == -1) continue;
			if (vec[j] == x){
				check=1;
				break;
			}
		}
		
		if (check) {
			//meore taroze unda iyos
			//jer washlaa
			valk[i] = 1;
		}
//		cout<<valk[i]<<" ";
		WriteAdvice(valk[i]);
	}
	
	for (int i = 0; i < n; i++){
		int x = C[i];
		bool check=0;
		
		for (int j = i + 1; j < n; j++){
			if (C[j] == x) break;
			if (vec[j] == -1) continue;
			if (vec[j] == x){
				check=1;
				break;
			}
		}
		
		if (check) {
			//meore taroze unda iyos
			//jer washlaa
			val[i] = 1;
		}
		
//		cout<<val[i]<<" ";
		WriteAdvice(val[i]);
	}
//	cout<<endl;
  	
//  	for (int i=0;i<k;i++){
//  		WriteAdvice(valk[i]);
//		cout<<valk[i]<<" ";
//	}
//  	cout<<endl;
//  	
//	for (int i=0;i<n;i++){
//		WriteAdvice(val[i]);
//		cout<<val[i]<<" ";
//	}
//	cout<<endl;
}
#include <bits/stdc++.h>
#include "assistant.h"
#define pb push_back
using namespace std;

int CC[2000005];
bool on[2000005];
int vall[2000005],vallk[2000005];

void Assist(unsigned char *A, int N, int K, int R) {
	int n=N;
	int k=K;
	
//	cout<<A[0]<<endl;
//	cout<<"read "<<R<<": ";
//	for (int i=0;i<R;i++)
//		cout<<A[i]<<"^ ";
//	cout<<endl;
	
	for (int i = 0; i < k; i++)
		vallk[i] = A[i];
	for (int i=0;i<n;i++)
		vall[i] = A[i+k];
	
	vector <int> t2;
	for (int i=0;i<k;i++){
		if (!vallk[i]) on[i] = 1;
		else t2.pb(i);
	}
	
	int i;
	int l = 0;
	for (i = 0; i < N; i++) {
    	int req = GetRequest();
    	if (on[req]){
    		if (!vall[i]) continue;
    		on[req] = 0;
    		t2.pb(req);
    		continue;
		}
		
//		cout<<"back "<<t2.back()<<endl;
		PutBack(t2.back());
		t2.pop_back();
		
		if (!vall[i]){
			on[req] = 1;
		}else{
			t2.pb(req);
		}
  	}
}

Compilation message

assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:32:6: warning: unused variable 'l' [-Wunused-variable]
   32 |  int l = 0;
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 47744 KB Output is correct
2 Correct 20 ms 47748 KB Output is correct
3 Correct 20 ms 47988 KB Output is correct
4 Correct 21 ms 48000 KB Output is correct
5 Correct 22 ms 48052 KB Output is correct
6 Correct 22 ms 48048 KB Output is correct
7 Correct 24 ms 48044 KB Output is correct
8 Correct 25 ms 48280 KB Output is correct
9 Correct 25 ms 48236 KB Output is correct
10 Correct 29 ms 48164 KB Output is correct
11 Correct 27 ms 48372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 48424 KB Output is correct
2 Correct 181 ms 50728 KB Output is correct
3 Correct 2348 ms 56904 KB Output is correct
4 Correct 67 ms 54280 KB Output is correct
5 Correct 100 ms 54268 KB Output is correct
6 Correct 445 ms 54516 KB Output is correct
7 Correct 1411 ms 55484 KB Output is correct
8 Correct 1406 ms 55712 KB Output is correct
9 Correct 59 ms 53160 KB Output is correct
10 Correct 2058 ms 56140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1075 ms 54048 KB Output is correct
2 Correct 1769 ms 55840 KB Output is correct
3 Correct 1729 ms 55856 KB Output is correct
4 Correct 1713 ms 55756 KB Output is correct
5 Correct 1458 ms 54696 KB Output is correct
6 Correct 1736 ms 55732 KB Output is correct
7 Correct 1777 ms 55636 KB Output is correct
8 Correct 1761 ms 56612 KB Output is correct
9 Correct 1702 ms 54576 KB Output is correct
10 Correct 1793 ms 55712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 48016 KB Output is correct
2 Correct 26 ms 48280 KB Output is correct
3 Correct 22 ms 48016 KB Output is correct
4 Correct 22 ms 48024 KB Output is correct
5 Correct 29 ms 48064 KB Output is correct
6 Correct 22 ms 48024 KB Output is correct
7 Correct 24 ms 48036 KB Output is correct
8 Correct 26 ms 48272 KB Output is correct
9 Correct 27 ms 48252 KB Output is correct
10 Correct 38 ms 48292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1417 ms 55612 KB Output is correct - 120000 bits used
2 Correct 1557 ms 55728 KB Output is correct - 122000 bits used
3 Correct 1737 ms 55872 KB Output is correct - 125000 bits used
4 Correct 1792 ms 55676 KB Output is correct - 125000 bits used
5 Correct 1736 ms 55856 KB Output is correct - 125000 bits used
6 Correct 1762 ms 55940 KB Output is correct - 125000 bits used
7 Correct 1822 ms 55860 KB Output is correct - 124828 bits used
8 Correct 1792 ms 55856 KB Output is correct - 124910 bits used
9 Correct 1844 ms 55820 KB Output is correct - 125000 bits used
10 Correct 1791 ms 56752 KB Output is correct - 125000 bits used