답안 #1012042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012042 2024-07-01T15:00:13 Z AmirAli_H1 최후의 만찬 (IOI12_supper) C++17
100 / 100
95 ms 12364 KB
// In the name of Allah

#include <bits/stdc++.h>
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);

static int n, k, m;
const static int maxn = 2e5 + 7;
static int A[maxn], val[maxn], ind[maxn];
static int M[maxn], res[maxn];
static set<pii> st;

void WriteAdvice(unsigned char a);

void ComputeAdvice(int C[], int Nx, int Kx, int Mx) {
	n = Nx; k = Kx; m = Mx;
	
	n += k;
	for (int i = 0; i < k; i++) A[i] = i;
	for (int i = k; i < n; i++) A[i] = C[i - k];
	
	fill(ind, ind + n, n);
	for (int i = n - 1; i >= 0; i--) {
		val[i] = ind[A[i]];
		ind[A[i]] = i;
	}
	
	st.clear();
	fill(M, M + n, -1); fill(res, res + n, 1);
	for (int i = 0; i < k; i++) {
		st.insert(Mp(val[i], i));
		M[A[i]] = i;
	}
	for (int i = k; i < n; i++) {
		int j = M[A[i]];
		if (j != -1) {
			st.erase(Mp(val[j], j));
			st.insert(Mp(val[i], i));
			M[A[i]] = i;
		}
		else {
			auto f = *st.rbegin();
			int r = f.S; st.erase(f);
			res[r] = 0; M[A[r]] = -1;
			st.insert(Mp(val[i], i));
			M[A[i]] = i;
		}
	}
	
	for (int i = 0; i < n; i++) {
		if (res[i]) WriteAdvice(1);
		else WriteAdvice(0);
	}
}
// In the name of Allah

#include <bits/stdc++.h>
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);

static int n, k, m;
const static int maxn = 2e5 + 7;
static int A[maxn], M[maxn];
static set<pii> st;

void PutBack(int T);

int GetRequest();

void Assist(unsigned char res[], int Nx, int Kx, int Rx) {
	n = Nx; k = Kx; m = Rx;
	n += k;
	
	fill(M, M + n, -1);
	for (int i = 0; i < k; i++) {
		st.insert(Mp(res[i], i));
		A[i] = i; M[A[i]] = i;
	}
	
	for (int i = k; i < n; i++) {
		A[i] = GetRequest();
		if (M[A[i]] != -1) {
			int j = M[A[i]];
			auto f = Mp(res[j], j); st.erase(f);
			M[A[i]] = -1;
		}
		else {
			auto f = *st.begin();
			int j = f.S; st.erase(f);
			M[A[j]] = -1; PutBack(A[j]);
		}
		st.insert(Mp(res[i], i));
		M[A[i]] = i;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3084 KB Output is correct
2 Correct 1 ms 2836 KB Output is correct
3 Correct 3 ms 2852 KB Output is correct
4 Correct 3 ms 2872 KB Output is correct
5 Correct 2 ms 2892 KB Output is correct
6 Correct 3 ms 3148 KB Output is correct
7 Correct 3 ms 3148 KB Output is correct
8 Correct 3 ms 3156 KB Output is correct
9 Correct 3 ms 3148 KB Output is correct
10 Correct 4 ms 3336 KB Output is correct
11 Correct 4 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3576 KB Output is correct
2 Correct 36 ms 6264 KB Output is correct
3 Correct 75 ms 12364 KB Output is correct
4 Correct 40 ms 8332 KB Output is correct
5 Correct 46 ms 8256 KB Output is correct
6 Correct 59 ms 8728 KB Output is correct
7 Correct 78 ms 10320 KB Output is correct
8 Correct 57 ms 10448 KB Output is correct
9 Correct 37 ms 8264 KB Output is correct
10 Correct 92 ms 11812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 8276 KB Output is correct
2 Correct 80 ms 10836 KB Output is correct
3 Correct 83 ms 11276 KB Output is correct
4 Correct 78 ms 11152 KB Output is correct
5 Correct 95 ms 10528 KB Output is correct
6 Correct 80 ms 11132 KB Output is correct
7 Correct 80 ms 11152 KB Output is correct
8 Correct 64 ms 11164 KB Output is correct
9 Correct 65 ms 11404 KB Output is correct
10 Correct 80 ms 11312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3124 KB Output is correct
2 Correct 5 ms 3152 KB Output is correct
3 Correct 3 ms 3152 KB Output is correct
4 Correct 3 ms 3144 KB Output is correct
5 Correct 3 ms 3152 KB Output is correct
6 Correct 3 ms 3268 KB Output is correct
7 Correct 3 ms 3156 KB Output is correct
8 Correct 4 ms 3160 KB Output is correct
9 Correct 4 ms 3156 KB Output is correct
10 Correct 6 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 9448 KB Output is correct - 120000 bits used
2 Correct 80 ms 9760 KB Output is correct - 122000 bits used
3 Correct 83 ms 9996 KB Output is correct - 125000 bits used
4 Correct 83 ms 9972 KB Output is correct - 125000 bits used
5 Correct 84 ms 10028 KB Output is correct - 125000 bits used
6 Correct 95 ms 9996 KB Output is correct - 125000 bits used
7 Correct 83 ms 9984 KB Output is correct - 124828 bits used
8 Correct 80 ms 10000 KB Output is correct - 124910 bits used
9 Correct 80 ms 9976 KB Output is correct - 125000 bits used
10 Correct 63 ms 9976 KB Output is correct - 125000 bits used