Submission #753853

# Submission time Handle Problem Language Result Execution time Memory
753853 2023-06-06T08:04:20 Z minhcool Last supper (IOI12_supper) C++17
100 / 100
184 ms 14320 KB
#include "advisor.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
//#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 3e5 + 5;
 
const int oo = 1e9 + 7, mod = 1e9 + 7;
 
 /*
mt19937 rng(1);
 
int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}*/
 
//set<ii> se;
 
map<int, int> mp;
 
int nxt[N];
 
int c[N];
 
bool cook[N];
int in[N];

int n, k, cur[N];
 
void ComputeAdvice(int *C, int N, int K, int M){
  n = N, k = K;
	for(int i = 0; i < k; i++) c[i] = i;
	for(int i = k; i < n + k; i++) c[i] = C[i - k];
	for(int i = n + k - 1; i >= 0; i--){
		if(mp.find(c[i]) == mp.end()) nxt[i] = oo;
		else nxt[i] = mp[c[i]];
		mp[c[i]] = i;
	}
	set<ii> se;
	for(int i = 0; i < n; i++) in[i] = -1;
	for(int i = 0; i < n + k; i++){
		if(in[c[i]] >= 0){
			se.erase({in[c[i]], c[i]});
			in[c[i]] = nxt[i];
			cur[c[i]] = i;
			se.insert({in[c[i]], c[i]});
		}
		else{
			if(se.size() == k){
			//	cout << i << " " << (*se.rbegin()).fi << " " << (*se.rbegin()).se << " " << cur[(*se.rbegin()).se] << "\n";
				int temp = (*se.rbegin()).se;
				cook[cur[temp]] = 1;
				in[temp] = -1;
				se.erase((*se.rbegin()));
			}
			in[c[i]] = nxt[i];
			cur[c[i]] = i;
			se.insert({in[c[i]], c[i]});
		}
	}
	for(int i = 0; i < n + k; i++){
	//	if(i <= 20) cout << i << " " << cook[i] << "\n";
		WriteAdvice(cook[i]);
	}
}
#include "assistant.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

mt19937 rng(1);

int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}


void Assist(unsigned char *A, int N, int K, int R){
	int n = N, k = K;
	set<int> cooking;
	set<int> ins;
	//cout << n + k << "\n";
	//for(int i = 0; i < n; i++) in[i] = -1;
	for(int i = 0; i < n + k; i++){
		int x;
		if(i < k) x = i; 
		else x = GetRequest();
		//cout << "HE " << x << "\n";
		if(ins.find(x) != ins.end()){
		//	cooking.erase(x);
			if(A[i]) cooking.insert(x);
		}
		else{
		//	cout << x << "\n";
		//	cout << "HOHOHO\n";
			if(ins.size() == k){
			//	assert(cooking.size());
				int temp = (*cooking.begin());
				cooking.erase(temp);
				ins.erase(temp);
				PutBack(temp);
			}
		//	cout << "HOHOHO2\n";
			if(A[i]) cooking.insert(x);
			ins.insert(x);
		//	cout << "HO\n";
		}
	//	cout << i << " " << ins.size() << " " << cooking.size() << "\n";
	}
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:61:17: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |    if(se.size() == k){
      |                 ^

assistant.cpp:19:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   19 | const int oo = 1e18 + 7, mod = 1e9 + 7;
      |                ~~~~~^~~
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:47:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |    if(ins.size() == k){
      |       ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 532 KB Output is correct
2 Correct 1 ms 652 KB Output is correct
3 Correct 3 ms 792 KB Output is correct
4 Correct 3 ms 676 KB Output is correct
5 Correct 5 ms 960 KB Output is correct
6 Correct 7 ms 1088 KB Output is correct
7 Correct 6 ms 960 KB Output is correct
8 Correct 7 ms 1312 KB Output is correct
9 Correct 9 ms 1092 KB Output is correct
10 Correct 8 ms 1220 KB Output is correct
11 Correct 8 ms 1196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1784 KB Output is correct
2 Correct 63 ms 4592 KB Output is correct
3 Correct 159 ms 14320 KB Output is correct
4 Correct 134 ms 9020 KB Output is correct
5 Correct 161 ms 8952 KB Output is correct
6 Correct 138 ms 9888 KB Output is correct
7 Correct 157 ms 11808 KB Output is correct
8 Correct 129 ms 11700 KB Output is correct
9 Correct 93 ms 6132 KB Output is correct
10 Correct 170 ms 13128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 10060 KB Output is correct
2 Correct 176 ms 12420 KB Output is correct
3 Correct 167 ms 12436 KB Output is correct
4 Correct 162 ms 12348 KB Output is correct
5 Correct 146 ms 11116 KB Output is correct
6 Correct 160 ms 12508 KB Output is correct
7 Correct 159 ms 12476 KB Output is correct
8 Correct 156 ms 13448 KB Output is correct
9 Correct 149 ms 11624 KB Output is correct
10 Correct 159 ms 12432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1076 KB Output is correct
2 Correct 8 ms 1220 KB Output is correct
3 Correct 7 ms 952 KB Output is correct
4 Correct 6 ms 968 KB Output is correct
5 Correct 8 ms 960 KB Output is correct
6 Correct 9 ms 1092 KB Output is correct
7 Correct 8 ms 1072 KB Output is correct
8 Correct 8 ms 1200 KB Output is correct
9 Correct 8 ms 1224 KB Output is correct
10 Correct 9 ms 1464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 12000 KB Output is correct - 120000 bits used
2 Correct 172 ms 12080 KB Output is correct - 122000 bits used
3 Correct 184 ms 12428 KB Output is correct - 125000 bits used
4 Correct 181 ms 12448 KB Output is correct - 125000 bits used
5 Correct 162 ms 12516 KB Output is correct - 125000 bits used
6 Correct 165 ms 12496 KB Output is correct - 125000 bits used
7 Correct 169 ms 12460 KB Output is correct - 124828 bits used
8 Correct 170 ms 12540 KB Output is correct - 124910 bits used
9 Correct 169 ms 12460 KB Output is correct - 125000 bits used
10 Correct 154 ms 13264 KB Output is correct - 125000 bits used