QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298125#3061. Donut Dronejucason_xuWA 4ms5748kbC++142.7kb2024-01-05 18:11:372024-01-05 18:11:37

Judging History

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

  • [2024-01-05 18:11:37]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5748kb
  • [2024-01-05 18:11:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rd(i,n) for(int i=0;i<n;i++)
#define rp(i,n) for(int i=1;i<=n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define st string
#define vt vector
#define pb push_back
//#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n,m,q,a[2005][2005],to[2005],f[2005][31];
inline bool best(int y,int x,int b,int c){
    return a[x][y]>a[b][y]&&a[x][y]>a[c][y];
}
inline int pre(int x){
    return (x-1+n)%n;
}
inline int nxt(int x){
    return (x+1)%n;
}
inline void move(int &a,int &b){
    if(best((b+1)%m,a,nxt(a),pre(a)));
    else if(best((b+1)%m,nxt(a),a,pre(a)))a=nxt(a);
    else a=pre(a);
    b=(b+1)%m;
}
inline int roll(int &l,int &r,int &c){
    if(l==r&&!best(c,l,pre(l),nxt(l)))return 0;
    if(l==(r-1+n)%n){
        if(best(c,l,pre(l),nxt(l)));
        else if(best(c,r,pre(r),nxt(r)));
        else if(best(c,l,nxt(l),nxt(nxt(l))));
        else if(best(c,r,pre(r),pre(pre(r))));
        else if(best(c,l,pre(l),pre(pre(l))));
        else if(best(c,r,nxt(r),nxt(nxt(r))));
        else return 0;
    }int L=l;
    if(best(c,l,pre(l),pre(pre(l))))l=(l-1+n)%n;
    else if(best(c,l,pre(l),nxt(l)));
    else if(l!=r&&best(c,nxt(l),l,pre(l)));
    else l=(l+1)%n;

    if(best(c,r,nxt(r),nxt(nxt(r))))r=(r+1)%n;
    else if(best(c,r,nxt(r),pre(r)));
    else if(L!=r&&best(c,pre(r),r,nxt(r)));
    else r=(r-1+n)%n;

    c=(c-1+m)%m;
    return 1;
}
inline void check(int x,int y){
    int l=y,r=y,c=x;
    int res=roll(l,r,c);
    if(!res)return;
    while(c!=0){
        res=roll(l,r,c);
        if(!res)return;
    }
    int a=y,b=x;
    while(b!=0)move(a,b);
    for(int i=l;i!=r;i=(i+1)%n)to[i]=a;
    to[r]=a;
}
inline void modify(int x,int y,int z){
    a[x][y]=z;
    rep(i,-2,2)check(y,(x+i+n)%n);
    rep(i,0,n-1)f[i][0]=to[i];
    rep(j,1,30)rep(i,0,n-1)f[i][j]=f[f[i][j-1]][j-1];
}
inline void move(int &x,int &y,int k){
    while(y!=0&&k){
        move(x,y);
        k--;
    }
    int d=(k/m);k%=m;
    per(i,0,30)if(d>>i&1)x=f[x][i];
    while(k){
        move(x,y);
        k--;
    }
}
string s;
int x,y,z,X,Y;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    x=0,y=0;
    cin>>n>>m;
    rd(i,n)rd(j,m)cin>>a[i][j];
    rd(i,n)check(0,i);
    rep(i,0,n-1)f[i][0]=to[i];
    rep(j,1,30)rep(i,0,n-1)f[i][j]=f[f[i][j-1]][j-1];
    cin>>q;
    rp(i,q){
        cin>>s;
        if(s=="move"){
            cin>>z;
            move(x,y,z);
            cout<<x+1<<" "<<y+1<<endl;
        }else{
            cin>>X>>Y>>z;
            modify(X-1,Y-1,z);
        }
    }
    return 0;
}
//Rain Rain Rain

详细

Test #1:

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

input:

4 4
1 2 9 3
3 5 4 8
4 3 2 7
5 8 1 6
4
move 1
move 1
change 1 4 100
move 1

output:

4 2
1 3
1 4

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

3 4
10 20 30 40
50 60 70 80
90 93 95 99
3
move 4
change 2 1 100
move 4

output:

3 1
2 1

result:

ok 2 lines

Test #3:

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

input:

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

output:

19 10
18 19
3 24
3 30
3 2
4 3
3 8
7 14
3 21
2 27
3 7
3 8
6 16
5 17
3 24
2 27
3 29
3 8
7 12
6 16
3 22
3 2
7 12
3 19
1 22
4 25
4 3
3 5
7 12
3 20
1 22
2 24
3 2
6 11
3 20
2 24
4 4
3 5
5 10
6 11
4 18
2 21
3 29
3 2
3 5
4 9
6 16
2 25
1 26
2 1
4 6
7 15
2 24
3 2
7 12
3 19
3 28
5 4
9 11
9 12
11 17
10 19
12 21...

result:

ok 1945 lines

Test #4:

score: -100
Wrong Answer
time: 4ms
memory: 5748kb

input:

50 50
126812431 909179109 607682292 96000160 425314080 189788877 721251789 103560861 114082307 888028612 277663589 257100764 842807257 327052508 652365304 770138116 384723035 680037089 675501229 509497026 174936063 991259231 761329528 658883078 806406343 741076652 973854314 192609094 398064987 65322...

output:

46 21
46 21
1 49
47 20
46 37
1 42
45 35
50 50
2 17
1 43
2 38
2 47
50 50
2 38
50 50
2 26
2 17
2 34
2 21
4 9
3 6
1 2
1 30
2 40
2 21
2 35
2 17
2 31
2 32
4 9
2 42
3 12
4 8
2 31
1 3
2 15
1 48
1 20
1 30
2 17
49 49
2 14
2 4
1 30
1 29
2 40
2 24
1 27
1 36
1 27
49 47
3 6
2 32
3 41
49 48
2 34
3 41
47 22
49 28
...

result:

wrong answer 297th lines differ - expected: '44 15', found: '50 15'