QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#510976 | #8651. Table Tennis | Max_s_xaM | 0 | 302ms | 29956kb | C++14 | 6.2kb | 2024-08-09 14:48:07 | 2024-08-09 14:48:07 |
Judging History
answer
#include <iostream>
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 = 5010, N = 5000;
int n; ll m;
bool e[MAXN][MAXN];
ll f[MAXN];
int a[MAXN][3];
inline int Calc()
{
int cnt = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
for (int k = j + 1; k <= n; k++)
if ((e[i][j] && e[j][k] && e[k][i]) || (e[j][i] && e[k][j] && e[i][k]))
cnt++;
return cnt;
}
inline void Link(int x, int y, int z, int ad)
{
for (int i = 1; i <= x; i++)
for (int j = x + 1; j <= x + y; j++)
e[i + ad][j + ad] = 1;
for (int i = x + 1; i <= x + y; i++)
for (int j = x + y + 1; j <= x + y + z; j++)
e[i + ad][j + ad] = 1;
for (int i = x + y + 1; i <= x + y + z; i++)
for (int j = 1; j <= x; j++)
e[i + ad][j + ad] = 1;
}
inline void Full(int n, int ad)
{
if (n <= 2) return;
int x = a[n][0], y = a[n][1], z = a[n][2];
Link(x, y, z, ad);
Full(x, ad), Full(y, ad + x), Full(z, ad + x + y);
}
inline void Solve(int n, int m, int ad)
{
if (m == 0) return;
if (n <= 8 && !(n == 8 && m == 17))
{
for (int z = 0; z <= n; z++)
for (int y = 0; y + z <= n; y++)
for (int x = 0; x + y + z <= n; x++)
if (x * y * z + f[x] + f[y] + f[z] == m) return Link(x, y, z, ad), Full(x, ad), Full(y, ad + x), Full(z, ad + x + y);
else if (x * y * z == m) return Link(x, y, z, ad);
else if (x * y * z + f[x] == m) return Link(x, y, z, ad), Full(x, ad);
else if (z && x * y * (z - 1) + f[x] + f[y] + f[z] == m) return Link(x, y, z - 1, ad), Full(x, ad), Full(y, ad + x), Full(z, ad + x + y);
cout << "Error " << n << ' ' << m << '\n';
return;
}
ll x = a[n][0], y = a[n][1], z = a[n][2];
if (x * y * (z - 1) < m)
{
if (m >= x * y * z) m -= x * y * z, Link(x, y, z, ad);
else
{
m -= x * y * (z - 1), Link(x, y, z - 1, ad);
ll _y = y;
while (x * _y > m) _y--;
for (int i = 1; i <= x; i++)
for (int j = x + 1; j <= x + _y; j++)
e[i + ad][j + ad] = 1;
for (int i = x + 1; i <= x + _y; i++)
e[i + ad][x + y + z + ad] = 1;
for (int i = 1; i <= x; i++)
e[x + y + z + ad][i + ad] = 1;
m -= x * _y;
}
if (m < f[x]) return Solve(x, m, ad);
m -= f[x], Full(x, ad);
if (m < f[y]) return Solve(y, m, ad + x);
m -= f[y], Full(y, ad + x);
if (m < f[z]) return Solve(z, m, ad + x + y);
m -= f[z], Full(z, ad + x + y);
return;
}
if (m <= x * y * (z - 1))
{
ll _z = z;
while (x * y * _z > m) _z--;
Link(x, y, _z, ad), m -= x * y * _z;
if (!m) return;
ll _y = y;
while (x * _y > m) _y--;
for (int i = 1; i <= x; i++)
for (int j = x + 1; j <= x + _y; j++)
e[i + ad][j + ad] = 1;
for (int i = x + 1; i <= x + _y; i++)
e[i + ad][x + y + z + ad] = 1;
for (int i = 1; i <= x; i++)
e[x + y + z + ad][i + ad] = 1;
m -= x * _y;
if (!m) return;
for (int i = 1; i <= m; i++)
e[i + ad][x + _y + 1 + ad] = e[x + y + z - 1 + ad][i + ad] = 1;
e[x + _y + 1 + ad][x + y + z - 1 + ad] = 1;
}
}
int main()
{
// freopen("C.in", "r", stdin);
// freopen("C.out", "w", stdout);
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
for (int i = 3; i <= N; i++)
{
a[i][0] = a[i][1] = a[i][2] = i / 3;
for (int j = 0; j < i % 3; j++) a[i][2 - j]++;
for (int j = 0; j < 3; j++) f[i] += f[a[i][j]];
f[i] += (ll)a[i][0] * a[i][1] * a[i][2];
}
int T;
Read(T);
while (T--)
{
Read(n), Read(m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
e[i][j] = 0;
if (f[n] < m) { cout << "No\n"; continue; }
Solve(n, m, 0);
cout << "Yes\n";
for (int i = 2; i <= n; i++, cout << "\n")
for (int j = 1; j < i; j++)
cout << e[i][j];
// int cnt = Calc();
// if (cnt != m) cout << "WA " << n << ' ' << m << ' ' << cnt << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 5ms
memory: 6212kb
input:
97 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 58 0 59 0 60 0 61 0 62 0 63 0...
output:
Yes 0 00 Yes 0 00 000 Yes 0 00 000 0000 Yes 0 00 000 0000 00000 Yes 0 00 000 0000 00000 000000 Yes 0 00 000 0000 00000 000000 0000000 Yes 0 00 000 0000 00000 000000 0000000 00000000 Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 00...
result:
ok good job! (97 test cases)
Test #2:
score: 5
Accepted
time: 299ms
memory: 28404kb
input:
5 4839 0 127 0 22 0 7 0 5 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (5 test cases)
Test #3:
score: 5
Accepted
time: 68ms
memory: 15152kb
input:
11 1191 0 1580 0 199 0 484 0 209 0 1226 0 92 0 5 0 4 0 4 0 6 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (11 test cases)
Test #4:
score: 5
Accepted
time: 85ms
memory: 14516kb
input:
8 953 0 1747 0 1782 0 213 0 210 0 82 0 10 0 3 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (8 test cases)
Test #5:
score: 5
Accepted
time: 1ms
memory: 5836kb
input:
1 6 0
output:
Yes 0 00 000 0000 00000
result:
ok good job! (1 test case)
Test #6:
score: 5
Accepted
time: 1ms
memory: 5900kb
input:
1 7 0
output:
Yes 0 00 000 0000 00000 000000
result:
ok good job! (1 test case)
Test #7:
score: 5
Accepted
time: 1ms
memory: 5800kb
input:
1 19 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000
result:
ok good job! (1 test case)
Test #8:
score: 5
Accepted
time: 1ms
memory: 7928kb
input:
1 20 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000
result:
ok good job! (1 test case)
Test #9:
score: 5
Accepted
time: 1ms
memory: 6372kb
input:
1 149 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (1 test case)
Test #10:
score: 5
Accepted
time: 1ms
memory: 6472kb
input:
1 150 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (1 test case)
Test #11:
score: 5
Accepted
time: 3ms
memory: 9904kb
input:
1 599 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (1 test case)
Test #12:
score: 5
Accepted
time: 3ms
memory: 10184kb
input:
1 600 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (1 test case)
Test #13:
score: 5
Accepted
time: 302ms
memory: 28500kb
input:
1 4999 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (1 test case)
Test #14:
score: 5
Accepted
time: 299ms
memory: 29956kb
input:
1 5000 0
output:
Yes 0 00 000 0000 00000 000000 0000000 00000000 000000000 0000000000 00000000000 000000000000 0000000000000 00000000000000 000000000000000 0000000000000000 00000000000000000 000000000000000000 0000000000000000000 00000000000000000000 000000000000000000000 0000000000000000000000 000000000000000000000...
result:
ok good job! (1 test case)
Test #15:
score: 0
Wrong Answer
time: 0ms
memory: 5888kb
input:
291 3 0 3 1 4 0 4 1 4 2 5 0 5 1 5 2 5 3 6 0 6 1 6 2 6 3 6 4 7 0 7 1 7 2 7 3 7 4 7 5 8 0 8 1 8 2 8 3 8 4 8 5 8 6 9 0 9 1 9 2 9 3 9 4 9 5 9 6 9 7 10 0 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 11 0 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 12 0 12 1 12 2 12 3 12 4 12 5 12 6 12 7 12 8 12 9 12 10 13 0 ...
output:
Yes 0 00 Yes 0 10 Yes 0 00 000 Yes 0 10 000 Yes 0 10 100 Yes 0 00 000 0000 Yes 0 10 000 0000 Yes 0 10 100 0000 Yes 0 00 000 1110 Yes 0 00 000 0000 00000 Yes 0 10 000 0000 00000 Yes 0 10 100 0000 00000 Yes 0 00 000 1110 00000 Yes 0 00 100 1000 00000 Yes 0 00 000 0000 00000 000000 Yes 0 10 000 0000 00...
result:
wrong answer expected 1 ways, but found 20 ways (test case 29)
Subtask #2:
score: 0
Wrong Answer
Test #58:
score: 4
Accepted
time: 1ms
memory: 5800kb
input:
1 4 4
output:
No
result:
ok good job! (1 test case)
Test #59:
score: 4
Accepted
time: 1ms
memory: 5736kb
input:
1 5 10
output:
No
result:
ok good job! (1 test case)
Test #60:
score: 4
Accepted
time: 1ms
memory: 5804kb
input:
1 6 20
output:
No
result:
ok good job! (1 test case)
Test #61:
score: 4
Accepted
time: 1ms
memory: 5824kb
input:
1 7 35
output:
No
result:
ok good job! (1 test case)
Test #62:
score: 4
Accepted
time: 1ms
memory: 7940kb
input:
1 5 10
output:
No
result:
ok good job! (1 test case)
Test #63:
score: 4
Accepted
time: 1ms
memory: 5808kb
input:
1 6 19
output:
No
result:
ok good job! (1 test case)
Test #64:
score: 4
Accepted
time: 1ms
memory: 5804kb
input:
1 6 20
output:
No
result:
ok good job! (1 test case)
Test #65:
score: 4
Accepted
time: 1ms
memory: 5904kb
input:
1 7 33
output:
No
result:
ok good job! (1 test case)
Test #66:
score: 4
Accepted
time: 1ms
memory: 5768kb
input:
1 7 33
output:
No
result:
ok good job! (1 test case)
Test #67:
score: 4
Accepted
time: 1ms
memory: 5796kb
input:
1 4 3
output:
No
result:
ok good job! (1 test case)
Test #68:
score: 4
Accepted
time: 1ms
memory: 5804kb
input:
1 5 8
output:
No
result:
ok good job! (1 test case)
Test #69:
score: 4
Accepted
time: 1ms
memory: 7836kb
input:
1 6 17
output:
No
result:
ok good job! (1 test case)
Test #70:
score: 4
Accepted
time: 1ms
memory: 5816kb
input:
1 7 30
output:
No
result:
ok good job! (1 test case)
Test #71:
score: 4
Accepted
time: 1ms
memory: 5732kb
input:
2 3 0 3 1
output:
Yes 0 00 Yes 0 10
result:
ok good job! (2 test cases)
Test #72:
score: 4
Accepted
time: 1ms
memory: 5736kb
input:
2 3 0 3 1
output:
Yes 0 00 Yes 0 10
result:
ok good job! (2 test cases)
Test #73:
score: 4
Accepted
time: 1ms
memory: 5816kb
input:
1 4 2
output:
Yes 0 10 100
result:
ok good job! (1 test case)
Test #74:
score: 0
Wrong Answer
time: 1ms
memory: 5800kb
input:
1 5 5
output:
No
result:
wrong answer you did't find a solution but jury did (test case 1)
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%