Submission
Status:
PPxxxxxxxx
Subtask/Task Score:
20/100
Score: 20
User: NovemNotes
Problemset: โชว์ของโลมา
Language: cpp
Time: 0.006 second
Submitted On: 2026-03-11 11:22:38
#include <bits/stdc++.h>
using namespace std;
const int N = 1009;
int n,cnt=1,idx=0;
int num[N][N];
vector<pair<int,int>> vp = {{0,1},{0,-1},{1,0},{-1,0}};
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n;
int i=0,j=0;
while(i<n||j<n){
if(i<-1||j<-1||i>n||j>n)break;
// cout << i << " " << j << "\n";
num[i][j] = cnt++;
i+=vp[idx%4].first;
j+=vp[idx%4].second;
if(num[i][j]!=0){
i-=vp[idx%4].first;
j-=vp[idx%4].second;
idx++;
i+=vp[idx%4].first;
j+=vp[idx%4].second;
continue;
}
else if(j==n){
i++;j=n-1;
idx++;
}else if(i==n){
j++,i=n-1;
idx++;
}else if(j==-1){
i++;
j=0;
idx++;
}
if(cnt==n*n+1)break;
}
int ans=0;
for(int j=0;j<n;j++){
ans += (num[n-1][j]%10);
}
cout << ans << "\n";
// for(int i=0;i<n;i++){
// for(int j=0;j<n;j++){
// cout << num[i][j] << " ";
// }
// cout << "\n";
// }
return 0;
}