0826

Done IOI Start at: 2026-8-26 19:00 2 hour(s) Host: 2
#include <bits/stdc++.h>
using namespace std;
int nxt[4][2]={0,1,1,0,0,-1,-1,0};
char mat[1005][1005];
int book[1005][1005];
int main(){
	int T;
	cin>>T;
	while(T--){
		memset(book,0,sizeof(book));
		int sx,sy,d;
		int n,m,k;
		cin>>n>>m>>k;
		cin>>sx>>sy>>d;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>mat[i][j];
			}
		}
		book[sx][sy] = 1;
		int nowx=sx,nowy=sy,dir=d;
		while(k){
			int nx = nowx+nxt[dir][0],ny=nowy+nxt[dir][1];
			if(nx>=1 && nx<=n && ny>=1 && ny<=m && mat[nx][ny]=='.'){
				nowx=nx,nowy=ny;
				book[nowx][nowy] = 1;
				k--;
			}
			else{
				dir = (dir+1)%4;
				k--;
			}
		}
		int res = 0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				res+=book[i][j];
			}
		}
		cout<<res<<endl;
	}
	return 0;
}
Status
Done
Rule
IOI
Problem
4
Start at
2026-8-26 19:00
End at
2026-8-26 21:00
Duration
2 hour(s)
Host
Partic.
2