QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#497470 | #7669. Maze Reduction | Max_s_xaM | WA | 1ms | 7880kb | C++14 | 4.0kb | 2024-07-29 09:32:03 | 2024-07-29 09:32:03 |
Judging History
answer
#include <iostream>
#include <vector>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 110, MAXM = 1e6 + 10;
int n;
vector <int> e[MAXN];
int id[MAXN][MAXN];
bool avl[MAXN]; int ans[MAXN];
int st[MAXM][3], top;
bool f[MAXN][MAXN][MAXN], vis[MAXN][MAXN][MAXN], inq[MAXN][MAXN][MAXN];
inline bool Solve(int u, int v, int d)
{
if (vis[u][v][d]) return f[u][v][d];
vis[u][v][d] = 1;
top++, st[top][0] = u, st[top][1] = v, st[top][2] = d;
inq[u][v][d] = 1;
if (e[u].size() != e[v].size()) return f[u][v][d] = 0;
bool flag = 1;
for (int i = 0, j = d; i < e[u].size(); i++, (++j == e[u].size()) && (j = 0))
{
int t = max(e[e[v][j]].size(), e[e[u][i]].size());
int dd = (id[e[v][j]][v] - id[e[u][i]][u] + t) % t;
if (inq[e[u][i]][e[v][j]][dd]) continue;
flag &= Solve(e[u][i], e[v][j], dd);
}
return f[u][v][d] = flag;
}
int main()
{
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n);
for (int i = 1; i <= n; i++)
{
int m; Read(m);
for (int j = 1, x; j <= m; j++) Read(x), e[i].push_back(x), id[i][x] = e[i].size() - 1;
}
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
{
int t = max(e[i].size(), e[j].size());
for (int k = 0; k < t; k++)
{
if (vis[i][j][k]) continue;
bool cur = Solve(i, j, k);
while (top) f[st[top][0]][st[top][1]][st[top][2]] = cur, inq[st[top][0]][st[top][1]][st[top][2]] = 0, top--;
}
}
bool flag = 0;
for (int i = 1; i <= n; i++)
if (!avl[i])
{
int cnt = 0;
ans[++cnt] = i;
for (int j = i + 1; j <= n; j++)
{
int t = max(e[i].size(), e[j].size());
for (int k = 0; k < t; k++)
if (f[i][j][k]) {ans[++cnt] = j; break;}
}
if (cnt > 1)
{
for (int i = 1; i <= cnt; i++) cout << ans[i] << ' ', avl[ans[i]] = 1; cout << '\n';
flag = 1;
}
}
if (!flag) cout << "none\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6008kb
input:
13 2 2 4 3 1 3 5 2 2 4 3 1 3 6 2 2 6 2 4 5 2 8 9 2 7 9 2 7 8 2 11 13 2 10 12 2 11 13 2 10 12
output:
2 4 5 6 7 8 9 10 11 12 13
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 7740kb
input:
6 3 3 4 5 0 1 1 1 1 2 1 6 1 5
output:
none
result:
ok single line: 'none'
Test #3:
score: 0
Accepted
time: 0ms
memory: 5956kb
input:
10 2 2 3 2 1 3 3 1 2 4 2 3 5 2 4 6 2 5 7 2 6 8 2 7 9 2 8 10 1 9
output:
none
result:
ok single line: 'none'
Test #4:
score: 0
Accepted
time: 1ms
memory: 7880kb
input:
10 2 2 3 2 1 3 3 1 2 4 2 3 5 2 4 6 2 5 7 2 6 8 3 7 9 10 2 8 10 2 8 9
output:
1 9 2 10 3 8 4 7 5 6
result:
ok 5 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 5764kb
input:
1 0
output:
none
result:
ok single line: 'none'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 5720kb
input:
2 0 0
output:
none
result:
wrong answer 1st lines differ - expected: '1 2', found: 'none'