# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
985219 | AdamGS | Table Tennis (JOI24_tabletennis) | C++17 | 608 ms | 16552 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=5e3+7;
bitset<LIM>T[LIM];
vector<pair<ll,ll>>merge(vector<pair<ll,ll>>A, vector<pair<ll,ll>>B) {
vector<pair<ll,ll>>P;
ll l=0;
for(auto i : A) {
while(l<B.size() && B[l]<i) {
P.pb(B[l]);
++l;
}
P.pb(i);
}
while(l<B.size()) {
P.pb(B[l]);
++l;
}
return P;
}
void solve() {
ll n, m;
cin >> n >> m;
rep(i, n) rep(j, n) T[i][j]=0;
vector<pair<ll,ll>>P;
rep(i, n) P.pb({i, i});
int a=0, b=n-1;
while(m && P[0].st+1<P[n-1].st) {
while(P[a+1].st==P[0].st) ++a;
vector<pair<ll,ll>>A, B;
if(P[n-1].st-P[0].st-1>m) {
for(int i=1; i<n; ++i) if(P[i].st-P[a].st-1==m) {
m-=P[i].st-P[a].st-1;
--P[i].st;
++P[a].st;
break;
}
} else {
m-=P[b].st-P[a].st-1;
++P[a].st;
--P[b].st;
}
while(P[a].st!=P[0].st) --a;
while(P[b].st!=P[n-1].st) ++b;
while(a<n-1 && P[a+1].st==P[0].st) ++a;
while(b>0 && P[b-1].st==P[n-1].st) --b;
}
if(m) {
cout << "No\n";
return;
}
cout << "Yes\n";
rep(i, n-1) {
vector<pair<ll,ll>>A, B;
for(int j=1; j<P.size(); ++j) {
if(j>P[0].st) {
--P[j].st;
T[P[0].nd][P[j].nd]=1;
T[P[j].nd][P[0].nd]=0;
B.pb(P[j]);
} else {
T[P[0].nd][P[j].nd]=0;
T[P[j].nd][P[0].nd]=1;
A.pb(P[j]);
}
}
P=merge(A, B);
}
for(int i=1; i<n; ++i) {
rep(j, i) cout << T[i][j];
cout << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int _=1;
cin >> _;
while(_--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |