QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#472702#8864. Ball PassingPetroTarnavskyi#RE 0ms0kbC++201.9kb2024-07-11 18:35:312024-07-11 18:35:32

Judging History

你现在查看的是最新测评结果

  • [2024-07-11 18:35:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-11 18:35:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

int n, k;
vector<VI> v;
VI c;
int idx = 0;

PII findmin()
{
	PII res = {-1, -1};
	FOR (id, idx, k)
	{
		FOR (pos, 0, SZ(v[id]))
		{
			if (res.F == -1 || v[res.F][res.S] > v[id][pos])
				res = {id, pos};
		}
	}
	return {res.F, SZ(v[res.F]) - res.S - 1};
}

void perenos(int i, int j, int sz)
{
	while (sz--)
	{
		cout << i + 1 << ' ' << j + 1 << '\n';
		v[j].PB(v[i].back());
		v[i].pop_back();
	}
}

void trash(int i, int sz, int banned)
{
	FOR (id, idx, k)
	{
		if (i == id || id == banned)
			continue;
		int can = min(sz, c[id] - SZ(v[id]));
		perenos(i, id, can);
		sz -= can;
	}
}

void f(int K, int cnt)
{
	int i = idx;
	int j = i;
	if (j == K) j++;
	if (SZ(v[j]) == c[j])
		trash(j, 1, -1);
	c[j]--;
	trash(K, cnt, -1);
	perenos(i, j, min(c[j] - SZ(v[j]), SZ(v[i])));
	c[j]++;
	perenos(K, j, 1);
	trash(i, SZ(v[i]), j);
	perenos(j, i, 1);
	v[i].pop_back();
	c[i]--;
	if (c[i] == 0)
		idx++;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	FOR (i, 0, k)
	{
		cin >> c[i];
		FOR (j, 0, c[i])
		{
			int x;
			cin >> x;
			if (x)
				v[i].PB(x);
		}
	}
	FOR (i, 0, n)
	{
		if (idx == k - 1)
		{
		}
		else
		{
			auto r = findmin();
			if (r.F == idx)
			{
				trash(idx, SZ(v[idx]), -1);
				r = findmin();
			}
			f(r.F, r.S);
		}
		cerr << i << '\n';
		FOR (j, 0, n)
		{
			for (auto a : v[j])
				cerr << a << ' ';
			cerr << '\n';
		}
		cerr << "------\n";
	}
	
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
BBGG
-1 -10
-10 -2
-8 7
7 -8

output:


result: