Submission

Status:

----xxxxxx

Subtask/Task Score:

0/100

Score: 0

User: 68019

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

Language: cpp

Time: 0.031 second

Submitted On: 2026-03-08 13:56:35

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N;
	cin >> N;

	vector<vector<int>> a(N, vector<int>(N));
	int num = 1;

	int top = 0, bottom = N - 1;
	int left = 0, right = N - 1;

	while (top <= bottom && left <= right) {
		for (int j = left; j <= right; j++)
			a[top][j] = num++;
		top++;

		for (int i = top; i <= bottom; i++)
			a[i][right] = num++;
		right--;

		if (top <= bottom) {
			for (int j = right; j >= left; j--)
				a[bottom][j] = num++;
			bottom--;
		}

		if (left <= right) {
			for (int i = bottom; i >= top; i--)
				a[i][left] = num++;
			left++;
		}
	}

	long long sum = 0;

	int r = N - 1, c = N - 1;

	while (r >= 0 && c >= 0) {
		sum += a[r][c] % 10;
		r--;
		c--;
	}

	cout << sum;
}