QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472702 | #8864. Ball Passing | PetroTarnavskyi# | RE | 0ms | 0kb | C++20 | 1.9kb | 2024-07-11 18:35:31 | 2024-07-11 18:35:32 |
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;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
4 BBGG -1 -10 -10 -2 -8 7 7 -8