提出 #35357489


ソースコード 拡げる

#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
//#define mp make_pair
//#define OO(x) fixed<<setprecision(x)
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=1010;
int n,a[1010][1010];
vector<int> v[2];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	if (n==3){
		cout<<"1 9 5\n3 6 4\n7 8 2\n";
		return 0;
	}
	if (n==4){
		cout<<"15 11 16 12\n13 3 6 9\n14 7 8 1\n4 2 10 5\n";
		return 0;
	}
	if (n==5){
		cout<<"25 23 21 19 17\n15 7 9 11 13\n5 3 1 14 12\n20 22 24 2 4\n6 8 10 16 18\n";
		return 0;
	}
	F(i,1,n*n){
		v[i&1].pb(i);
	}
	sort(v[0].begin(),v[0].end(),[&](int x,int y){
		return x%3>y%3;
	});
	sort(v[1].begin(),v[1].end(),[&](int x,int y){
		return x%3>y%3;
	});
	int x=1,y=0;
	for (int z:v[1]){
		y++;
		if (y>n) y-=n,x++;
		a[x][y]=z;
	}
	x=n; y=n+1;
	for (int z:v[0]){
		y--;
		if (y<1) y+=n,x--;
		a[x][y]=z;
	}
	F(i,1,n){
		F(j,1,n){
			cout<<a[i][j]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

提出情報

提出日時
問題 C - Avoid Prime Sum
ユーザ yangziheng
言語 C++ (GCC 9.2.1)
得点 500
コード長 1615 Byte
結果 AC
実行時間 127 ms
メモリ 15312 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 1
AC × 24
セット名 テストケース
Sample 01_sample_01.txt
All 01_sample_01.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 04_max_01.txt, 04_max_02.txt, 04_max_03.txt, 04_max_04.txt, 04_max_05.txt
ケース名 結果 実行時間 メモリ
01_sample_01.txt AC 8 ms 3468 KiB
02_small_01.txt AC 4 ms 3640 KiB
02_small_02.txt AC 2 ms 3512 KiB
02_small_03.txt AC 2 ms 3568 KiB
02_small_04.txt AC 2 ms 3544 KiB
02_small_05.txt AC 2 ms 3604 KiB
02_small_06.txt AC 2 ms 3548 KiB
02_small_07.txt AC 2 ms 3608 KiB
02_small_08.txt AC 2 ms 3616 KiB
03_rand_01.txt AC 78 ms 9264 KiB
03_rand_02.txt AC 11 ms 4468 KiB
03_rand_03.txt AC 14 ms 4648 KiB
03_rand_04.txt AC 30 ms 5320 KiB
03_rand_05.txt AC 99 ms 12480 KiB
03_rand_06.txt AC 29 ms 5484 KiB
03_rand_07.txt AC 85 ms 10928 KiB
03_rand_08.txt AC 22 ms 5072 KiB
03_rand_09.txt AC 57 ms 7784 KiB
03_rand_10.txt AC 17 ms 4832 KiB
04_max_01.txt AC 127 ms 15224 KiB
04_max_02.txt AC 123 ms 15244 KiB
04_max_03.txt AC 123 ms 15256 KiB
04_max_04.txt AC 124 ms 15260 KiB
04_max_05.txt AC 122 ms 15312 KiB