QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#335071#3061. Donut DronezxcenWA 0ms3712kbC++172.1kb2024-02-22 16:59:392024-02-22 16:59:39

Judging History

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

  • [2024-02-22 16:59:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2024-02-22 16:59:39]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>

using namespace std;
const int N=2e3;
int n,m;
int a[N+10][N+10];
int to[N+10];
int q;
int ax,ay;
int vis[N+10];
inline pii move(int x,int y){
	y=(y+1)%m;
	int rx=x;
	if(a[(x+n-1)%n][y]>a[rx][y]){
		rx=(x+n-1)%n;
	}
	if(a[(x+1)%n][y]>a[rx][y]){
		rx=(x+1)%n;
	}
	return {rx,y};
}
inline pii solve(int x,int y){
	do{
		pii res=move(x,y);
		x=res.first;
		y=res.second;
	}while(y);
	return {x,y};
}
inline pii from(int x,int y){
	int ls=x,rs=x;
	do{
		y=(y+m-1)%m;
		int lm=ls-1,rm=rs+1;
		ls=lm;
		while(ls<=rm&&(move((ls%n+n)%n,y).first<lm||rm<move((ls%n+n)%n,y).first)){
			++ls;
		}
		rs=rm;
		while(rs>=lm&&(move((rs%n+n)%n,y).first<lm||rm<move((rs%n+n)%n,y).first)){
			--rs;
		}
		if(ls>rs){
			return {1,0};
		}
	}while(y);
	return {ls,rs};
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;++i){
		for(int j=0;j<m;++j){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<n;++i){
		to[i]=solve(i,0).first;
	}
	ax=0;
	ay=0;
	cin>>q;
	while(q--){
		char op[10];
		cin>>op;
		if(op[0]=='m'){
			int x;
			cin>>x;
			while(ay&&x){
				pii res=move(ax,ay);
				ax=res.first;
				ay=res.second;
				--x;
			}
			if(!x){
				cout<<"!";
				cout<<ax+1<<' '<<ay+1<<'\n';
			}
			else{
				for(int i=0;i<n;++i){
					vis[i]=0;
				}
				int sum=0;
				while(!vis[ax]&&x>=m){
					vis[ax]=++sum;
					ax=to[ax];
					x-=m;
				}
				if(x<m){
					while(x--){
						pii res=move(ax,ay);
						ax=res.first;
						ay=res.second;
					}
					cout<<"!!";
					cout<<ax+1<<' '<<ay+1<<'\n';
				}
				else{
					x=x%((sum-vis[ax]+1)*m);
					while(x>=m){
						ax=to[ax];
						x-=m;
					}
					while(x--){
						pii res=move(ax,ay);
						ax=res.first;
						ay=res.second;
					}
					cout<<"!!!";
					cout<<ax+1<<' '<<ay+1<<'\n';
				}
			}
		}
		else{
			int x,y,z;
			cin>>x>>y>>z;
			--x;
			--y;
			a[x][y]=z;
			pii res=from(x,y),res1=solve(x,y);
			for(int i=res.first;i<=res.second;++i){
				to[(i%n+n)%n]=res1.first;
			}
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3712kb

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:

wrong answer 1st lines differ - expected: '4 2', found: '!!4 2'