QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#511133 | #3402. Box Relations | PetroTarnavskyi# | AC ✓ | 19ms | 4440kb | C++20 | 1.9kb | 2024-08-09 16:41:07 | 2024-08-09 16:41:07 |
Judging History
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;
void dfs(int v, const vector<VI>& g, VI& used, VI& order)
{
used[v] = 1;
for (int to : g[v])
{
if (!used[to])
dfs(to, g, used, order);
}
order.PB(v);
}
void solve()
{
vector<vector<VI>> g(3, vector<VI>(2 * n));
// x[2 * i] = l[i], x[2 * i + 1] = r[i]
FOR(i, 0, n)
{
FOR(p, 0, 3)
{
// l[i] < r[i]
g[p][2 * i + 1].PB(2 * i);
}
}
while (k--)
{
char t;
int i, j;
cin >> t >> i >> j;
i--;
j--;
if (t == 'I')
{
FOR(p, 0, 3)
{
// l[i] < r[j], l[j] < r[i]
g[p][2 * j + 1].PB(2 * i);
g[p][2 * i + 1].PB(2 * j);
}
}
else
{
// r[i] < l[j]
g[t - 'X'][2 * j].PB(2 * i + 1);
}
}
vector<VI> vals(3, VI(2 * n));
bool ok = true;
FOR(p, 0, 3)
{
VI used(2 * n);
VI order;
FOR(i, 0, 2 * n)
if (!used[i])
dfs(i, g[p], used, order);
FOR(i, 0, 2 * n)
vals[p][order[i]] = i;
FOR(v, 0, 2 * n)
{
for (int to : g[p][v])
{
ok &= vals[p][v] > vals[p][to];
}
}
}
if (!ok)
{
cout << "IMPOSSIBLE\n\n";
return;
}
cout << "POSSIBLE\n";
FOR(i, 0, n)
{
FOR(t, 0, 2)
{
FOR(p, 0, 3)
{
if (t > 0 || p > 0)
cout << " ";
cout << vals[p][2 * i + t];
}
}
cout << "\n";
}
cout << "\n";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
for (int tc = 1; ; tc++)
{
cin >> n >> k;
if (n == 0 && k == 0)
break;
cout << "Case " << tc << ": ";
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 19ms
memory: 4440kb
input:
3 3 X 1 2 X 2 3 I 1 3 2 2 X 1 2 X 2 1 10 18 X 10 4 X 10 4 Y 2 8 X 7 4 Z 10 7 X 5 10 Z 2 10 X 6 10 I 8 3 X 10 9 Z 2 10 Y 5 4 Z 2 10 Y 10 3 Z 4 8 X 7 4 Y 10 4 X 5 8 828 99000 Y 757 547 X 47 555 Z 78 768 X 784 676 X 368 320 X 194 468 X 31 366 Z 105 405 Z 679 327 X 406 570 X 39 530 Y 69 130 Y 624 190 X ...
output:
Case 1: IMPOSSIBLE Case 2: IMPOSSIBLE Case 3: POSSIBLE 0 0 0 1 1 1 2 2 2 3 3 3 4 6 4 8 8 8 15 11 5 16 12 6 5 9 9 6 10 10 9 13 11 10 14 12 13 15 15 14 16 16 7 7 7 17 17 17 18 18 18 19 19 19 11 4 13 12 5 14 Case 4: IMPOSSIBLE Case 5: POSSIBLE 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9...
result:
ok Accepted! (29 test cases)