답안 #913805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913805 2024-01-20T09:42:34 Z Faisal_Saqib 최후의 만찬 (IOI12_supper) C++17
61 / 100
235 ms 15876 KB
#pragma once
#include "advisor.h"
#include <vector>
#include <cmath>
#include <map>
#include <set>
using namespace std;
/*
1	8	N≤5000 M=65000bits
2	9	N≤100000 M=2000000bits
3	9	N≤100000 M=1500bits K≤25000
4	35	N≤5000 M=10000bits
5	up to 39	N≤100000 M=1800000bits K≤25000

*/
void ComputeAdvice(int *c, int n, int k, int m)
{
	// cout<<"ASD\n";
	vector<int> pos[n];
	for(int j=0;j<n;j++)
		pos[j].push_back(1e9);
	for(int i=n-1;i>=0;i--)
		pos[c[i]].push_back(i);
	set<pair<int,int>> hap;
	map<int,int> color_to_index;
	vector<int> ap;
	for(int i=0;i<k;i++)
	{
		// cout<<"Hola "<<-pos[i].back()<<' '<<i<<endl;
		hap.insert({-pos[i].back(),i});
		color_to_index[i]=i;
		ap.push_back(i);
	}
	int lg=log2(k);	
	int last=-1;
	for(int j=0;j<n;j++)
	{
		if(color_to_index.find(c[j])==color_to_index.end())
		{
			pos[c[j]].pop_back();
			auto pt1=begin(hap);
			if(last!=-1 and pos[ap[last]].back()==(-1*(pt1->first)))
				pt1=hap.find({-pos[ap[last]].back(),ap[last]});
			auto it=*pt1;
			hap.erase(pt1);
			int npd=color_to_index[it.second];
			// cout<<"Rem "<<-it.first<<' '<<it.second<<" ind ";
			// cout<<npd<<endl;
			WriteAdvice((last==npd));
			for(int l=lg;l>=0 and last!=npd;l--)
			{
				if(npd&(1ll<<l))
				{
					WriteAdvice(1);	
				}
				else
				{
					WriteAdvice(0);
				}
			}
			last=npd;
			color_to_index.erase(it.second);
			// cout<<"Adding "<<pos[c[j]].back()<<' '<<c[j]<<' '<<npd<<endl;
			hap.insert({-pos[c[j]].back(),c[j]});
			color_to_index[c[j]]=npd;
			ap[npd]=c[j];
		}
		else
		{
			hap.erase({-pos[c[j]].back(),c[j]});
			pos[c[j]].pop_back();
			hap.insert({-pos[c[j]].back(),c[j]});
		}
	}	
}
#pragma once
#include "assistant.h"
#include <vector>
#include <cmath>
#include <map>
#include <set>
using namespace std;
/*
1	8	N≤5000 M=65000bits
2	9	N≤100000 M=2000000bits
3	9	N≤100000 M=1500bits K≤25000
4	35	N≤5000 M=10000bits
5	up to 39	N≤100000 M=1800000bits K≤25000

*/
void Assist(unsigned char *a, int n, int k, int r)
{
	vector<int> ans;
	set<int> hap;
	for(int i=0;i<k;i++)
	{
		hap.insert(i);
		ans.push_back(i);
	}
	int lg=log2(k);
	int p=0;
	int last=-1;
	for(int j=0;j<n;j++)
	{
		int x=GetRequest();
		if(hap.find(x)!=hap.end())
			continue;
		int ind=0;
		int dop=a[p];
		if(dop)
			ind=last;
		p++;
		for(int l=lg;l>=0 and dop==0;l--)
		{
			ind*=2;
			ind+=(a[p]);
			p++;
		}
		PutBack(ans[ind]);
		last=ind;
		hap.erase(ans[ind]);
		hap.insert(x);
		ans[ind]=x;
	}
}

Compilation message

advisor.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~

assistant.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 780 KB Output is correct
2 Correct 0 ms 784 KB Output is correct
3 Correct 3 ms 792 KB Output is correct
4 Correct 3 ms 1072 KB Output is correct
5 Correct 3 ms 1104 KB Output is correct
6 Correct 8 ms 1328 KB Output is correct
7 Correct 5 ms 1340 KB Output is correct
8 Correct 4 ms 1356 KB Output is correct
9 Correct 7 ms 1360 KB Output is correct
10 Correct 7 ms 1368 KB Output is correct
11 Correct 7 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1948 KB Output is correct
2 Correct 82 ms 6896 KB Output is correct
3 Correct 177 ms 15452 KB Output is correct
4 Correct 100 ms 10224 KB Output is correct
5 Correct 168 ms 11040 KB Output is correct
6 Correct 201 ms 12444 KB Output is correct
7 Correct 217 ms 14572 KB Output is correct
8 Correct 100 ms 11668 KB Output is correct
9 Correct 81 ms 11108 KB Output is correct
10 Correct 214 ms 15876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 11960 KB Output is correct
2 Correct 218 ms 15248 KB Output is correct
3 Correct 198 ms 14984 KB Output is correct
4 Correct 217 ms 15188 KB Output is correct
5 Correct 178 ms 14764 KB Output is correct
6 Correct 207 ms 15028 KB Output is correct
7 Correct 235 ms 15156 KB Output is correct
8 Correct 123 ms 13592 KB Output is correct
9 Correct 167 ms 15672 KB Output is correct
10 Correct 197 ms 14992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1104 KB Output is correct
2 Correct 5 ms 1208 KB Output is correct
3 Correct 6 ms 1184 KB Output is correct
4 Correct 4 ms 1252 KB Output is correct
5 Incorrect 2 ms 1072 KB Error - advice is too long
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 14644 KB Output is partially correct - 367511 bits used
2 Correct 207 ms 14696 KB Output is partially correct - 358338 bits used
3 Correct 211 ms 15124 KB Output is partially correct - 344123 bits used
4 Correct 228 ms 15280 KB Output is partially correct - 345172 bits used
5 Correct 179 ms 15112 KB Output is partially correct - 345604 bits used
6 Correct 200 ms 15172 KB Output is partially correct - 343862 bits used
7 Correct 190 ms 15088 KB Output is partially correct - 343326 bits used
8 Correct 218 ms 15084 KB Output is partially correct - 343731 bits used
9 Correct 208 ms 15148 KB Output is partially correct - 344627 bits used
10 Correct 157 ms 13528 KB Output is correct - 85848 bits used