Submission

Status:

x-x-xxxxxx

Subtask/Task Score:

0/100

Score: 0

User: Gunto

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

Language: cpp

Time: 0.062 second

Submitted On: 2026-03-05 14:48:03

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<vector<int>> m(n,vector<int> (n,0));
    int out=1;
    int strat1=0,strat2=0;
    int end1=n-1,end2=n-1;
    while(out<=(n*n)){
        //left to right
        int tem=strat2;
        for(int i=strat2;i<=end2;++i){
            m[strat1][i]=out;
            //using strat2 to run
            strat2++;
            out++;
        }end2=tem;
        strat1++;
        //right to left 
        for(int i=strat2-1;i>=end2;--i){
            m[strat1][i]=out;
            out++;
        }
        strat1++;
        //up to down
        
        strat2=end2;
        for(int i=strat1;i<n;++i){
            m[i][strat2]=out;
            out++;
        }
        strat2++;
        end1=strat1;
        strat1=n-1;
        //down to up
        for(int i=strat1;i>=end1;--i){
            m[i][strat2]=out;
            out++;
        }//must reset
        strat2++;
        strat1=strat2;
        end1=n-1;
        end2=n-1;   
    }
    if(m[n-1][n-1]==0) m[n-1][n-1]=out;
    //succeses
    for(auto k:m){
        for(int kk:k)cout<<kk<<" ";
        cout<<endl;
    }
    //m[n-1]
    int sum=0;
    for(int i=0;i<n;++i){
        int num=m[n-1][i]%10;
        sum+=num;
    }
    cout<<sum;
    return 0;
}