QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#611313#8940. Piggy SortXY_ElevenRE 4ms8312kbC++236.4kb2024-10-04 20:20:032024-10-04 20:20:04

Judging History

你现在查看的是最新测评结果

  • [2024-10-04 20:20:04]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:8312kb
  • [2024-10-04 20:20:03]
  • 提交

answer

#include <bits/stdc++.h>
// #include <windows.h>
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int> 
#define pli pair<LL,int> 
#define vct vector 
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{
}
cint N=510,L=N*N*N;
int n,m,tot;
LL sum[N],sum2[N];
array <LL,N> a[N],a_[N];
int h[N];
struct Num
{
    int x,y;
    short i,j,k;
    void gt()
    {
        int g=gcd(x,y);
        x/=g,y/=g;
    }
    bool operator < (const Num &A) const
    {
        return (1ll*x*A.y<1ll*y*A.x);
    }
    bool operator == (const Num &A) const
    {
        return (1ll*x*A.y==1ll*y*A.x);
    }
}c[L];
bool vis[N][N],vis2[N];
pair<Num,LL> z[N];
int f[N],f2[N];
vct <pii> d[N];
void work(int l,int r)
{
    For(i,1,n) d[i].clear();
    For(t,l,r)
    {
        auto [x,y,i,j,k]=c[t];
        d[k].pb({i,j});
    }
    For(k,1,n)
    {
        exc(sz(d[k])<m-1);
        int cnt=0;
        for(auto [i,j]:d[k])
            if((!vis[i][j])&&(!vis2[i]))
                cnt++,vis2[i]=true;
        // printf("cnt=%d\n",cnt);
        if(cnt==m-1)
        {
            z[k]={{c[l].x,c[l].y},k};
            for(auto [i,j]:d[k])
                if(vis2[i]&&(!vis[i][j]))
                {
                    // printf("%d,%d\n",i,j);
                    vis[i][j]=true,vis2[i]=false;
                }
        }
        for(auto [i,j]:d[k])
            vis2[i]=false;
    }
}
void main_solve()
{
    inpr(n,m);
    if(n==1)
    {
        For(i,1,m) For(j,1,n) { int t; inint(t); };
        outint(1);
        return ;
    }
    For(i,1,m)
    {
        sum[i]=0ll,h[i]=i;
        For(j,1,n)
            inll(a_[i][j]),sum[i]+=a_[i][j];
    }
    sort(h+2,h+m+1,[&](cint &w1,cint &w2)->bool{return sum[w1]<sum[w2];});
    For(i,1,m) For(j,1,n) a[i][j]=a_[h[i]][j];
    For(i,1,m) sum2[i]=sum[h[i]];
    For(i,1,m) swap(sum[i],sum2[i]);
    For(i,2,m) sum[i]-=sum[1]; sum[1]=0ll;
    tot=0;
    For(i,2,m) For(j,1,n) For(k,1,n)
    {
        if(a[i][j]>=a[1][k])
        {
            LL x=a[i][j]-a[1][k],y=sum[i],g=gcd(x,y);
            x/=g,y/=g;
            c[++tot]={x,y,i,j,k};
        }
    }
    For(i,2,m) For(j,1,n) vis[i][j]=false;
    sort(c+1,c+tot+1);
    reverse(c+1,c+tot+1);
    For(i,1,n) z[i]={{0ll,0ll},0};
    /*For(t,1,tot)
    {
        auto [x,y,i,j,k]=c[t];
        printf("%lld,%lld %d,%d,%d\n",x,y,i,j,k);
    }*/
    vct <pii> range;
    for(int l=1,r;l<=tot;l=r+1)
    {
        r=l; while(r<tot&&c[r+1]==c[r]) r++;
        exc(r-l+1<m-1);
        range.pb({l,r});
    }
    sort(all(range),[&](const pii &w1,const pii &w2)->bool{return (w1.sc-w1.ft<w2.sc-w2.ft);});
    for(auto [l,r]:range) work(l,r);
    // For(i,1,n)
    // {
    //     if(!z[i].ft.y)
    //         while(true);
    // }
    // For(i,1,n) printf("%lld,%lld\n",z[i].ft.x,z[i].ft.y);
    For(i,1,n) f[i]=i;
    sort(f+1,f+n+1,[&](cint &w1,cint &w2)->bool{return z[w1]<z[w2];});
    For(i,1,n) f2[f[i]]=i;
    For(i,1,n) outint_(f2[i]);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    // srand(time(NULL));
    main_init();
    int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*

*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7972kb

input:

3
2 4
1 2
3 4
5 6
7 8
1 2
1
1
3 4
1 2 3
6 9 9
10 15 17
12 18 21

output:

1 2
1
3 1 2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 4ms
memory: 8048kb

input:

41
1 2
-19
9531
2 3
11 13
3175 4759
2211 3313
10 19
-54 -25 -19 -18 -1 3 61 63 85 88
-54 753 863 2397 3111 4649 4671 4756 5507 7762
-54 369 479 1245 1575 2345 2367 2452 2819 3922
-54 553 663 1797 2311 3449 3471 3556 4107 5762
-54 87 197 399 447 653 675 760 845 1102
-54 320 430 1098 1379 2051 2073 21...

output:

1
1 2
1 2 6 10 5 7 9 4 3 8
8 7 5 9 2 1 6 3 4
1 6 5 9 8 2 3 10 4 7
3 5 10 6 7 4 9 8 2 1
4 3 1 8 2 5 6 7
3 1 5 2 6 9 8 7 4 10
2 3 1 4
3 2 9 1 4 6 7 5 8
1 5 2 6 7 3 4 8 9
9 8 5 7 2 3 4 6 1
1 2 4 8 5 7 10 6 9 3
7 1 3 2 9 8 10 4 5 6
7 8 1 2 5 6 3 9 4
8 1 2 7 6 9 3 5 4
8 1 2 4 5 10 9 3 6 7
6 4 1 8 7 9 10 ...

result:

ok 41 lines

Test #3:

score: 0
Accepted
time: 4ms
memory: 8312kb

input:

46
8 12
-50 -35 -20 -10 -9 4 13 91
-24 30 32 143 146 147 173 221
-44 -8 10 13 26 27 61 103
-46 -12 -3 8 14 15 45 99
-22 32 36 147 158 159 189 237
-47 -14 -11 7 8 9 37 97
-31 18 23 104 105 117 129 165
-45 -10 5 9 20 21 53 101
-36 8 18 74 75 77 119 125
-30 20 24 110 111 125 131 173
-48 -19 -16 2 3 6 2...

output:

1 7 3 5 6 2 8 4
1 2 3
3 6 1 5 10 8 7 2 9 4
2 5 3 6 9 10 8 7 1 4
1 4 5 2 6 3 7
8 6 4 5 7 9 2 3 1
6 7 2 8 9 1 10 3 5 4
4 5 1 3 2
1 2
1 2 4 5 7 6 3 8 9
6 3 4 9 7 1 2 8 10 5
1 6 7 8 4 9 5 3 2
1 4 2 6 5 8 3 7
2 1
5 1 7 6 3 2 4
7 3 8 4 1 2 9 5 6 10
6 1 2 5 3 4
2 1 3 4
7 8 5 9 2 1 4 3 6
7 8 9 3 5 4 1 6 2 1...

result:

ok 46 lines

Test #4:

score: 0
Accepted
time: 4ms
memory: 8040kb

input:

48
3 4
-4952 -1539 836
-4294 5909 12778
-4811 57 3395
-4529 3249 8513
8 11
-9107 -1143 1324 3936 4088 4381 7658 9440
-2753 531 6032 14986 18097 18264 20240 22022
-5224 -120 5276 9673 12692 12763 15347 17129
-2047 717 6248 16504 19621 19856 21638 23420
-6283 -399 4952 7396 10304 10477 13250 15032
-48...

output:

1 2 3
3 1 6 8 2 7 4 5
8 4 6 1 2 9 10 5 3 7
1 2 3
6 1 10 7 5 3 9 4 8 2
1 2
8 3 2 7 10 6 1 9 5 4
9 5 2 7 6 1 8 4 3
6 4 3 2 7 5 1
1 4 2 3
1
3 8 9 6 7 4 1 2 10 5
5 1 6 4 2 3
2 1 9 6 4 5 3 8 7
3 5 6 7 9 2 4 8 1
4 2 1 3 5 6
4 5 6 3 7 1 2
1
9 7 10 1 8 5 3 6 2 4
8 3 6 9 2 5 4 7 1
4 3 9 5 7 6 2 1 8
1
4 2 7 5...

result:

ok 48 lines

Test #5:

score: 0
Accepted
time: 3ms
memory: 8032kb

input:

40
10 20
-4289879 -3663596 -3442064 -3379220 -670906 -329052 1547135 1640345 2662172 3577480
-4280827 -3609576 -3374758 -3321039 -598417 -319197 1583489 1685532 2700424 3645662
-4276115 -3581456 -3339722 -3290753 -560683 -314067 1602413 1709054 2720336 3681154
-4271279 -3552596 -3303764 -3259670 -52...

output:

1 6 8 7 10 2 3 5 4 9
2 3 1
9 8 3 6 4 2 10 1 7 5
2 1 8 5 3 4 10 7 6 9
7 2 6 1 9 5 8 3 4
2 6 3 9 7 1 4 5 8
3 6 7 5 1 2 8 4
3 4 10 9 8 7 6 2 5 1
3 8 2 6 1 4 5 7
4 2 5 7 1 6 3
1 8 3 10 9 7 4 6 5 2
1 3 5 4 2
8 6 7 3 1 4 5 10 2 9
1 2 3
5 10 2 7 6 4 1 8 3 9
4 10 7 6 8 9 5 1 2 3
5 7 10 1 4 9 3 6 2 8
4 2 1 3...

result:

ok 40 lines

Test #6:

score: -100
Runtime Error

input:

79
5 7
-5 -1 7 8 10
-1 1 10 19 20
-1 4 10 25 26
-1 5 10 27 28
-2 -1 10 13 14
-4 -1 9 10 10
-1 3 10 23 24
5 6
-7 -5 2 3 5
2 3 11 13 14
-5 -3 2 3 6
2 3 7 9 12
2 3 3 5 10
2 3 5 7 11
3 4
-10 -7 -5
-10 1 3
-10 -4 -2
-10 0 2
5 10
-10 -6 -1 6 7
-10 4 7 9 11
-10 7 8 13 13
-10 7 14 16 19
-10 7 12 15 17
-10 6...

output:


result: