結果

問題 No.1571 All Your Cycles Are Same Lengths
ユーザー kotatsugamekotatsugame
提出日時 2021-06-30 07:01:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 761 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 66,868 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 15:59:22
合計ジャッジ時間 1,771 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    5 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int Q,N,T;
int A[8][8];
main()
{
	cin>>Q;
	for(;Q--;)
	{
		cin>>N>>T;
		if(N==2)
		{
			if(T%2==0)
			{
				cout<<"Yes"<<endl;
				cout<<"1 2 "<<T/2<<endl;
			}
			else cout<<"No"<<endl;
			continue;
		}
		int a=2,b=N,c=N-2;
		bool fn=false;
		for(int x=0;!fn&&a*x<=T;x++)
		{
			for(int y=0;!fn&&a*x+b*y<=T;y++)
			{
				int rest=T-a*x-b*y;
				if(rest%c!=0)continue;
				int z=rest/c;
				fn=true;
				for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)
				{
					A[i][j]=0;
					if(i==0)A[i][j]+=x;
					A[i][j]+=y;
					if(i!=0)A[i][j]+=z;
				}
			}
		}
		if(fn)
		{
			cout<<"Yes"<<endl;
			for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)
			{
				cout<<i+1<<" "<<j+1<<" "<<A[i][j]<<endl;
			}
		}
		else cout<<"No"<<endl;
	}
}
0