Submission

Status:

PPPPxxxxxx

Subtask/Task Score:

40/100

Score: 40

User: Nay-O

Problemset: โชว์ของโลมา

Language: cpp

Time: 0.032 second

Submitted On: 2026-03-15 21:52:40

#include<bits/stdc++.h>
using namespace std;
using pii = array<int,3>;

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;
	vector<vector<int>> arr(n,vector<int>(n,-1));
	
	queue<pii> q;
	q.push({0,0,0}); // 0 right 1 left 2 down 3 up
	int c = 0;
	while(c<n*n){
		int a = q.front()[0], b = q.front()[1], d = q.front()[2];
		q.pop();
		while(arr[a][b]==-1){
			c++;
			arr[a][b]=c;
			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});
	}
	
	int ans = 0;
	
	
	for(int i = 0; i < n; i++){
		ans += arr[n-1][i]%10;
	}
	cout << ans;
	
	return 0;
}