結果

問題 No.3765 321-avoiding Grid
コンテスト
ユーザー sdtkwxt
提出日時 2026-10-16 22:03:29
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 28 ms / 1,000 ms
+ 386µs
コード長 1,233 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,903 ms
コンパイル使用メモリ 360,948 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-10-16 22:03:39
合計ジャッジ時間 5,816 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:17:69: warning: narrowing conversion of 'rnd.std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::operator()()' from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   17 |         for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)b[++bcnt]={i,j,rnd()};
      |                                                                  ~~~^~

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#define CSP2026 using
#define RP namespace
#define PLUSPLUS std
CSP2026 RP PLUSPLUS;
#define debug(x) cout<<"clock="<<clock()<<' '<<#x<<'='<<(x)<<'\n'
//#define getchar getchar_unlocked
using ll=long long;
inline int rd(){int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+(ch^48);return x*f;}
inline ll rdll(){ll x=0;int f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+(ch^48);return x*f;}
constexpr int N=505;
int a[N][N],bcnt;
mt19937 rnd(time(0)^random_device{}());
struct node{int x,y,t;}b[N*N];
signed main(){
	int n=rd(),A=rd(),B=rd(),C=rd();
	for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)b[++bcnt]={i,j,rnd()};
	sort(b+1,b+bcnt+1,[](const node &p1,const node &p2)->bool{
		return p1.x+p1.y==p2.x+p2.y?p1.t<p2.t:p1.x+p1.y<p2.x+p2.y;
	});
	
	if(C<A){
		for(int i=1;i<=C;++i)a[b[i].x][b[i].y]=3;
		for(int i=C+1;i<=C+A;++i)a[b[i].x][b[i].y]=1;
	}else{
		for(int i=1;i<=A;++i)a[b[i].x][b[i].y]=1;
		for(int i=A+1;i<=C+A;++i)a[b[i].x][b[i].y]=3;
	}
	for(int i=C+A+1;i<=n*n;++i)a[b[i].x][b[i].y]=2;
	for(int i=1;i<=n;++i,putchar(10))for(int j=1;j<=n;++j)cout<<a[i][j];
}
0