제출 #1328750

#제출 시각아이디문제언어결과실행 시간메모리
1328750user736482Table Tennis (JOI24_tabletennis)C++20
100 / 100
570 ms37248 KiB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define INF 1000000001LL
#define POT (1LL<<23)
#define INFL 1000000000000000099LL
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define pip pair<ll,pii>
#define ppp pair<pii,pii>
#define vi vector<ll>
#define vii vector<pii>
#define vvi vector<vi>
#define al(x) x.begin(),x.end()
#define rev(x) reverse(al(x))
#define X 18
#define FCTCST 7
template<typename T, typename U>
pair<T, U> operator+(const pair<T, U>& a, const pair<T, U>& b) {
    return {a.first + b.first, a.second + b.second};
}
template<typename T, typename U>
pair<T, U> operator-(const pair<T, U>& a, const pair<T, U>& b) {
    return {a.first - b.first, a.second - b.second};
}
template<typename T, typename U,typename Z>
pair<T, U> operator*(const pair<T, U>& a, const Z& b) {
    return {a.first*b, a.second*b};
}
template<typename T, typename U,typename Z>
pair<T, U> operator/(const pair<T, U>& a, const Z& b) {
    return {a.first/b, a.second/b};
}
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"{"<<p.ff<<", "<<p.ss<<"}";
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    for (size_t i = 0; i < v.size(); ++i) {
        if (i) os << ", ";
        os << v[i];
    }
    os << "}";
    return os;
}
template<ll MOD=998244353>
struct mint_t{
    ll x;
    mint_t(ll y=0){x=y%MOD;if(x<0)x+=MOD;}
    mint_t& operator+=(const mint_t& a){if((x+=a.x)>=MOD)x-=MOD;return *this;}
    mint_t& operator-=(const mint_t& a){if((x+=MOD-a.x)>=MOD)x-=MOD;return *this;}
    mint_t operator+(const mint_t& a)const{mint_t res(*this);return res+=a;}
    mint_t operator-(const mint_t& a)const{mint_t res(*this);return res-=a;}
    mint_t& operator*=(const mint_t& a){(x*=a.x)%=MOD;return *this;}
    mint_t operator*(const mint_t& a)const{mint_t res(*this);return res*=a;}
    mint_t fp(ll y)const{
        mint_t a=1,b=x;
        while(y){
            if(y&1)a*=b;
            b*=b;
            y/=2;
        }
        return a;
    }
    mint_t& operator/=(const mint_t& a){(*this)*=a.fp(MOD-2);return *this;}
    mint_t operator/(const mint_t& a)const{mint_t res(*this);return res/=a;}
};
#define mint mint_t<>
template<long long MOD>
istream& operator>>(istream& in, mint_t<MOD>& a){
    ll x;
    in>>x;
    a=mint_t<MOD>(x);
    return in;
}
template<long long MOD>
istream& operator<<(istream& out, mint_t<MOD>& a){
    out<<a.x;
    return out;
}
mint fct[FCTCST];
mint bnm(ll a,ll b){
    if(b>a || a<0)return 0;
    return fct[a]/fct[b]/fct[a-b];
}
bool ed[5001][5001];
ll mn(ll x,ll y){
    ll bs=x/y;
    ll l1=y-x%y;
    ll l2=x%y;
    return l1*bs*bs+l2*(bs+1)*(bs+1);
}
void solve(){
    ll n,m;
    cin>>n>>m;
    m=n*(n-1)*(n-2)/3+n*(n-1)/2-2*m;
    
    //cout<<m<<"\n";
    vii dg;
    ll poz=(n)*(n-1)/2;
    if(m<mn(poz,n)){
        cout<<"No\n";
        return;
    }
    cout<<"Yes\n";
    for(ll i=0;i<n;i++){
        ll poz2=n-i;
        ll y=(poz+poz2-1)/poz2;
        //cout<<i<<" "<<n<<" "<<y<<" "<<poz<<" "<<poz2<<"\n";
        for(ll j=y+1;j<=n;j++){
            if(poz-j<(poz2-1)*(poz2-2)/2 || mn(poz-j,poz2-1)+j*j>m){
                //cout<<i<<" "<<j<<"i ";
                dg.pb({j-1,i+1});
                m-=(j-1)*(j-1);
                poz-=(j-1);
                break;
            }
        }
    }
    //cout<<dg;
    for(ll i=0;i<n;i++){
        sort(al(dg));
        //cout<<dg<<"\n";
        for(ll j=0;j<dg.back().ff;j++){
            if(dg[j].ss<dg.back().ss)ed[dg[j].ss][dg.back().ss]=0;
            else ed[dg.back().ss][dg[j].ss]=1;
        }
        for(ll j=dg.back().ff;j<dg.size()-1;j++){
            dg[j].ff--;
            if(dg[j].ss<dg.back().ss)ed[dg[j].ss][dg.back().ss]=1;
            else ed[dg.back().ss][dg[j].ss]=0;
        }
        dg.pop_back();
    }
    for(ll i=2;i<=n;i++){
        for(ll j=1;j<i;j++){
            cout<<ed[j][i];
        }
        cout<<"\n";
    }
}
int main(){
    fct[0]=1;
    for(ll i=1;i<FCTCST;i++)fct[i]=fct[i-1]*i;
    ll t=1;
    cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...