Submission
Status:
----xxxxxx
Score: 0
User: Punnawith
Problemset: โชว์ของโลมา
Language: cpp
Time: 0.050 second
Submitted On: 2025-03-22 20:10:53
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> board(N, vector<int>(N));
int num = 1, row = 0, col = 0;
// Define movement boundaries
int left = 0, right = N - 1, top = 0, bottom = N - 1;
while (num <= N * N) {
// Move right
for (col = left; col <= right; col++) board[top][col] = num++;
top++; // Move boundary inward
// Move left
for (col = right, row = top; row <= bottom; row++) board[row][col] = num++;
right--; // Move boundary inward
// Move down
for (row = bottom, col = right; col >= left; col--) board[row][col] = num++;
bottom--; // Move boundary inward
// Move up
for (row = bottom, col = left; row >= top; row--) board[row][col] = num++;
left++; // Move boundary inward
}
// Compute sum of last digits in the last row
int sumLastDigits = 0;
for (int i = 0; i < N; i++) {
sumLastDigits += board[N - 1][i] % 10;
}
cout << sumLastDigits;
return 0;
}