QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#536205 | #8651. Table Tennis | lfyszy | 0 | 0ms | 3976kb | C++14 | 4.4kb | 2024-08-28 19:58:49 | 2024-08-28 19:58:50 |
answer
// O(N^2) steps, each in O(1)
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
Int c2(Int n) {
return n*(n-1)/2;
}
Int c3(Int n) {
return n*(n-1)*(n-2)/6;
}
Int minK(Int n) {
return (n & 1) ? (n * c2(n/2)) : ((n/2) * c2(n/2 - 1) + (n/2) * c2(n/2));
}
vector<string> solveMin(int N) {
if (N & 1) {
vector<string> a(N, string(N, '0'));
for (int u = 0; u < N; ++u) {
int v = u;
for (int i = 1; i <= N/2; ++i) {
if (++v == N) v = 0;
a[u][v] = '1';
}
}
return a;
} else {
auto a = solveMin(N + 1);
a.pop_back();
for (int u = 0; u < N; ++u) a[u].pop_back();
return a;
}
}
vector<string> solve(int N, Int K) {
if (!(minK(N) <= K && K <= c3(N))) return {};
Int k;
vector<string> a;
{
Int sum = 0;
int n = N;
for (; n && minK(n-1) + c2(n-1) + sum <= K; --n) sum += c2(n-1);
k = minK(n) + sum;
a = solveMin(n-1);
for (int u = 0; u < n; ++u) a[u].resize(N, '0');
a.resize(N, string(N, '0'));
for (int u = n; u < N; ++u) for (int v = 0; v < u; ++v) a[u][v] = '1';
}
vector<vector<int>> uss(N);
for (int u = 0; u < N; ++u) {
int d = 0;
for (int v = 0; v < N; ++v) if (a[u][v] == '1') ++d;
uss[d].push_back(u);
}
vector<int> inq(N + 1, 0);
queue<int> que;
for (int d = 0; d < N; ++d) if (uss[d].size() >= 2) {
inq[d] = 1;
que.push(d);
}
for (; k < K; ++k) {
const int d = que.front();
que.pop();
inq[d] = 0;
int u = uss[d].back(); uss[d].pop_back();
int v = uss[d].back(); uss[d].pop_back();
swap(a[u][v], a[v][u]);
if (a[u][v] == '1') swap(u, v);
uss[d - 1].push_back(u);
uss[d + 1].push_back(v);
for (int dd = d - 1; dd <= d + 1; ++dd) if (uss[dd].size() >= 2) {
if (!inq[dd]) {
inq[dd] = 1;
que.push(dd);
}
}
}
return a;
}
void stress() {
for (int N = 0; N <= 30; ++N) {
cerr << "N = " << N << ": " << minK(N) << " <= K <= " << c3(N) << endl;
for (Int K = 0; K <= c3(N); ++K) {
const auto adj = solve(N, K);
if (minK(N) <= K && K <= c3(N)) {
assert((int)adj.size() == N);
for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) assert(adj[u][v] == '0' || adj[u][v] == '1');
for (int u = 0; u < N; ++u) assert(adj[u][u] == '0');
for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) if (u != v) assert(adj[u][v] != adj[v][u]);
Int score = 0;
for (int u = 0; u < N; ++u) for (int v = 0; v < N; ++v) for (int w = 0; w < N; ++w) {
if (adj[u][v] == '1' && adj[u][w] == '1' && adj[v][w] == '1') ++score;
}
assert(score == K);
} else {
assert(!adj.size());
}
}
}
}
int main() {
// stress(); return 0;
for (int numCases; ~scanf("%d", &numCases); ) for (int caseId = 1; caseId <= numCases; ++caseId) {
int N;
Int K;
scanf("%d%lld", &N, &K);
K = c3(N) - K;
const auto adj = solve(N, K);
if (adj.size()) {
puts("Yes");
for (int u = 1; u < N; ++u) {
puts(adj[u].substr(0, u).c_str());
}
} else {
puts("No");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
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:
result:
Subtask #2:
score: 0
Runtime Error
Test #58:
score: 4
Accepted
time: 0ms
memory: 3752kb
input:
1 4 4
output:
No
result:
ok good job! (1 test case)
Test #59:
score: 4
Accepted
time: 0ms
memory: 3748kb
input:
1 5 10
output:
No
result:
ok good job! (1 test case)
Test #60:
score: 4
Accepted
time: 0ms
memory: 3676kb
input:
1 6 20
output:
No
result:
ok good job! (1 test case)
Test #61:
score: 4
Accepted
time: 0ms
memory: 3676kb
input:
1 7 35
output:
No
result:
ok good job! (1 test case)
Test #62:
score: 4
Accepted
time: 0ms
memory: 3680kb
input:
1 5 10
output:
No
result:
ok good job! (1 test case)
Test #63:
score: 4
Accepted
time: 0ms
memory: 3616kb
input:
1 6 19
output:
No
result:
ok good job! (1 test case)
Test #64:
score: 4
Accepted
time: 0ms
memory: 3944kb
input:
1 6 20
output:
No
result:
ok good job! (1 test case)
Test #65:
score: 4
Accepted
time: 0ms
memory: 3752kb
input:
1 7 33
output:
No
result:
ok good job! (1 test case)
Test #66:
score: 4
Accepted
time: 0ms
memory: 3976kb
input:
1 7 33
output:
No
result:
ok good job! (1 test case)
Test #67:
score: 4
Accepted
time: 0ms
memory: 3592kb
input:
1 4 3
output:
No
result:
ok good job! (1 test case)
Test #68:
score: 4
Accepted
time: 0ms
memory: 3748kb
input:
1 5 8
output:
No
result:
ok good job! (1 test case)
Test #69:
score: 4
Accepted
time: 0ms
memory: 3648kb
input:
1 6 17
output:
No
result:
ok good job! (1 test case)
Test #70:
score: 4
Accepted
time: 0ms
memory: 3616kb
input:
1 7 30
output:
No
result:
ok good job! (1 test case)
Test #71:
score: 0
Runtime Error
input:
2 3 0 3 1
output:
result:
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%