結果

問題 No.942 プレゼント配り
ユーザー kotatsugame
提出日時 2019-12-09 02:03:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 70,344 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-03 05:31:22
合計ジャッジ時間 2,648 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
    5 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N,K;
main()
{
	cin>>N>>K;
	int t=N/K;
	if(K==1)
	{
		cout<<"Yes"<<endl;
		for(int i=1;i<=N;i++)cout<<i<<" ";
		cout<<endl;
	}
	else if(t%2==0)
	{
		cout<<"Yes"<<endl;
		for(int i=0;i<K;i++)
		{
			for(int j=0;j<t;j++)
			{
				cout<<(j%2==0?j*K+i+1:j*K+K-i)<<" ";
			}
			cout<<endl;
		}
	}
	else if(t>3&&N%2==1)
	{
		cout<<"Yes"<<endl;
		vector<vector<int> >X(2,vector<int>(K));
		for(int i=0;i<=K/2;i++)
		{
			X[0][i]=i+1;
			X[1][K-i-1]=2*K-i;
		}
		for(int i=0;i<K/2;i++)
		{
			X[1][i]=K/2+2+i*2;
			X[0][K/2+1+i]=K/2+3+i*2;
		}
		for(int i=0;i<K;i++)
		{
			cout<<X[0][i]<<" "<<X[1][i];
			for(int j=2;j<t/2;j++)
			{
				cout<<" "<<(j*K+1+i);
			}
			for(int j=t/2;j<t;j++)
			{
				cout<<" "<<(j*K+K-i);
			}
			cout<<endl;
		}
	}
	else if(t==3&&N%2==1)
	{
		cout<<"Yes"<<endl;
		vector<vector<int> >X(K,vector<int>(3));
		for(int i=0;i<K;i++)X[i][0]=i+1;
		int t=K/2;
		for(int i=0;i<K;i++)X[(i+t+1)%K][1]=K+i+1;
		for(int i=0;i<t;i++)X[K-i-1][2]=2*K+2+i*2;
		for(int i=0;i<=t;i++)X[t-i][2]=2*K+1+i*2;
		for(int i=0;i<K;i++)
		{
			cout<<X[i][0]<<" "<<X[i][1]<<" "<<X[i][2]<<endl;
		}
	}
	else cout<<"No"<<endl;
}
0