Submission
Status:
xxxxxxxxxx
Subtask/Task Score:
0/100
Score: 0
User: Nay-O
Problemset: โชว์ของโลมา
Language: cpp
Time: 0.001 second
Submitted On: 2026-03-15 22:04:39
#include<bits/stdc++.h>
using namespace std;
using pii = array<int,3>;
const int N = 1e4+5;
bool vis[N][N];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin>> n;
queue<pii> q;
q.push({0,0,0}); // 0 right 1 left 2 down 3 up
int c = 0;
int ans = 0;
while(c<n*n){
int a = q.front()[0], b = q.front()[1], d = q.front()[2];
q.pop();
while(!vis[a][b]){
c++;
vis[a][b]=true;
if(a == n-1){
ans += c%10;
}
a+=dy[d];
b+=dx[d];
if(a<0||b<0||a>n-1||b>n-1){
break;
}
}
a-=dy[d];
b-=dx[d];
if(d==0||d==1){
a++;
}
else{
b++;
}
q.push({a,b,(d+1)%4});
}
cout << ans;
return 0;
}