Submission #641070

# Submission time Handle Problem Language Result Execution time Memory
641070 2022-09-15T23:26:53 Z ymm Carnival (CEOI14_carnival) C++17
100 / 100
22 ms 324 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 160;
int ans[N];
int n;

int ask(vector<int> v)
{
	cout << v.size() << ' ';
	for (int x : v)
		cout << x+1 << ' ';
	cout << '\n';
	int ans;
	cin >> ans;
	return ans;
}

void solve(vector<int> v)
{
	int len = v.size();
	if (len == 1)
		return;
	solve(vector<int>(v.begin(), v.begin() + len/2));
	solve(vector<int>(v.begin() + len/2, v.end()));
	vector<vector<int>> cl, cr;
	Loop (i,0,len/2) {
		while (ans[v[i]] >= cl.size())
			cl.emplace_back();
		cl[ans[v[i]]].push_back(v[i]);
	}
	Loop (i,len/2,len) {
		while (ans[v[i]] >= cr.size())
			cr.emplace_back();
		cr[ans[v[i]]].push_back(v[i]);
		ans[v[i]] += cl.size();
	}
	Loop (i,0,cl.size())
		assert(cl[i].size());
	Loop (i,0,cr.size())
		assert(cr[i].size());
	vector<int> rem;
	Loop (i,0,cl.size()) {
		int l = 0, r = cr.size();
		while (l < r) {
			int m = (l + r + 1)/2;
			vector<int> vec;
			vec.push_back(cl[i][0]);
			Loop (j,l,m) vec.push_back(cr[j][0]);
			if (ask(vec) != vec.size())
				r = m-1;
			else
				l = m;
		}
		if (l < cr.size()) {
			for (int x : cr[l])
				ans[x] = i;
			rem.push_back(l + cl.size());
		}
	}
	sort(rem.begin(), rem.end());
	for (int x : v) {
		ans[x] -= lower_bound(rem.begin(), rem.end(), ans[x]) - rem.begin();
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	vector<int> vec(n);
	iota(vec.begin(), vec.end(), 0);
	solve(vec);
	cout << "0 ";
	Loop (i,0,n)
		cout << ans[i]+1 << ' ';
	cout << '\n';
}

Compilation message

carnival.cpp: In function 'void solve(std::vector<int>)':
carnival.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   while (ans[v[i]] >= cl.size())
      |          ~~~~~~~~~~^~~~~~~~~~~~
carnival.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   while (ans[v[i]] >= cr.size())
      |          ~~~~~~~~~~^~~~~~~~~~~~
carnival.cpp:2:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
carnival.cpp:43:2: note: in expansion of macro 'Loop'
   43 |  Loop (i,0,cl.size())
      |  ^~~~
carnival.cpp:2:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
carnival.cpp:45:2: note: in expansion of macro 'Loop'
   45 |  Loop (i,0,cr.size())
      |  ^~~~
carnival.cpp:2:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    2 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
      |                                        ^
carnival.cpp:48:2: note: in expansion of macro 'Loop'
   48 |  Loop (i,0,cl.size()) {
      |  ^~~~
carnival.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    if (ask(vec) != vec.size())
      |        ~~~~~~~~~^~~~~~~~~~~~~
carnival.cpp:60:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   if (l < cr.size()) {
      |       ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 208 KB Output is correct
2 Correct 17 ms 208 KB Output is correct
3 Correct 15 ms 320 KB Output is correct
4 Correct 18 ms 320 KB Output is correct
5 Correct 3 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 10 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 208 KB Output is correct
2 Correct 13 ms 316 KB Output is correct
3 Correct 12 ms 324 KB Output is correct
4 Correct 19 ms 320 KB Output is correct
5 Correct 4 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 6 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Output is correct
2 Correct 7 ms 208 KB Output is correct
3 Correct 11 ms 324 KB Output is correct
4 Correct 14 ms 320 KB Output is correct
5 Correct 4 ms 208 KB Output is correct
6 Correct 6 ms 208 KB Output is correct
7 Correct 13 ms 220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 5 ms 208 KB Output is correct
3 Correct 19 ms 320 KB Output is correct
4 Correct 22 ms 324 KB Output is correct
5 Correct 6 ms 208 KB Output is correct
6 Correct 10 ms 324 KB Output is correct
7 Correct 14 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 9 ms 208 KB Output is correct
3 Correct 15 ms 320 KB Output is correct
4 Correct 13 ms 208 KB Output is correct
5 Correct 9 ms 316 KB Output is correct
6 Correct 13 ms 208 KB Output is correct
7 Correct 16 ms 324 KB Output is correct