Submission
Status:
PPPPxxxxxx
Score: 40
User: Punnawith
Problemset: โชว์ของโลมา
Language: cpp
Time: 0.045 second
Submitted On: 2025-03-23 12:12:00
#include <iostream>
#include <vector>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<vector<int>> board(N, vector<int>(N, 0));
int num = 1;
int row = 0, col = 0;
while (num <= N * N) {
while (col < N && board[row][col] == 0) {
board[row][col] = num++;
col++;
}
col--; row++;
while (col >= 0 && row < N && board[row][col] == 0) {
board[row][col] = num++;
col--;
}
col++; row++;
while (row < N && col < N && board[row][col] == 0) {
board[row][col] = num++;
row++;
}
row--; col++;
while (row >= 0 && col < N && board[row][col] == 0) {
board[row][col] = num++;
row--;
}
row++; col++;
}
int sumLastDigits = 0;
for (int i = 0; i < N; i++) {
int number = board[N - 1][i];
int digits = number % 10;
sumLastDigits += digits;
}
cout << sumLastDigits;
return 0;
}