結果

問題 No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ
ユーザー kotatsugamekotatsugame
提出日時 2024-02-23 22:17:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,315 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 82,892 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-02-23 22:18:15
合計ジャッジ時間 26,496 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 109 ms
6,676 KB
testcase_02 AC 106 ms
6,676 KB
testcase_03 AC 102 ms
6,676 KB
testcase_04 AC 99 ms
6,676 KB
testcase_05 AC 94 ms
6,676 KB
testcase_06 AC 94 ms
6,676 KB
testcase_07 AC 92 ms
6,676 KB
testcase_08 AC 91 ms
6,676 KB
testcase_09 AC 92 ms
6,676 KB
testcase_10 AC 91 ms
6,676 KB
testcase_11 AC 93 ms
6,676 KB
testcase_12 AC 93 ms
6,676 KB
testcase_13 AC 96 ms
7,424 KB
testcase_14 AC 93 ms
8,576 KB
testcase_15 AC 92 ms
7,108 KB
testcase_16 AC 94 ms
6,676 KB
testcase_17 AC 105 ms
6,676 KB
testcase_18 AC 95 ms
6,784 KB
testcase_19 AC 96 ms
7,424 KB
testcase_20 AC 95 ms
8,704 KB
testcase_21 AC 96 ms
8,704 KB
testcase_22 AC 94 ms
8,704 KB
testcase_23 AC 94 ms
8,576 KB
testcase_24 AC 93 ms
8,576 KB
testcase_25 AC 94 ms
8,576 KB
testcase_26 AC 93 ms
8,704 KB
testcase_27 AC 109 ms
8,704 KB
testcase_28 AC 96 ms
8,704 KB
testcase_29 AC 99 ms
8,704 KB
testcase_30 AC 98 ms
8,704 KB
testcase_31 AC 99 ms
8,704 KB
testcase_32 AC 95 ms
8,576 KB
testcase_33 AC 98 ms
8,576 KB
testcase_34 AC 109 ms
8,704 KB
testcase_35 AC 106 ms
8,704 KB
testcase_36 AC 95 ms
8,576 KB
testcase_37 AC 96 ms
8,576 KB
testcase_38 AC 95 ms
8,576 KB
testcase_39 AC 106 ms
8,704 KB
testcase_40 AC 106 ms
8,168 KB
testcase_41 AC 89 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int N,L;
int X[2<<17],Y[2<<17];
vector<pair<int,int> >solve(int K)
{
	assert(1<=K&&K<=L);
	vector<vector<pair<int,int> > >T(K+1);
	const int W=L/K;
	for(int i=0;i<N;i++)
	{
		int v=(2*X[i]+W)/(2*W);
		T[min(v,K)].push_back(make_pair(X[i],Y[i]));
	}
	vector<pair<int,int> >ret;
	ret.reserve(N);
	for(int i=0;i<=K;i++)
	{
		if(i%2==0)
		{
			sort(T[i].begin(),T[i].end(),[](const pair<int,int>&l,const pair<int,int>&r){
				return l.second<r.second;
			});
		}
		else
		{
			sort(T[i].begin(),T[i].end(),[](const pair<int,int>&l,const pair<int,int>&r){
				return l.second>r.second;
			});
		}
		for(pair<int,int>p:T[i])ret.push_back(p);
	}
	assert(ret.size()==N);
	long long sum=0;
	for(int i=0;i<N;i++)
	{
		int x=ret[i].first,y=ret[i].second;
		int ni=i+1<N?i+1:0;
		int nx=ret[ni].first,ny=ret[ni].second;
		sum+=abs(x-nx);
		sum+=abs(y-ny);
	}
	if(sum>1000LL*L)ret.clear();
	return ret;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;cin>>T;
	for(;T--;)
	{
		cin>>N>>L;
		for(int i=0;i<N;i++)cin>>X[i]>>Y[i];
		int K=min(500,L);
		vector<pair<int,int> >ans=solve(K);
		while(ans.empty())ans=solve(--K);
		cout<<N<<"\n";
		for(int i=0;i<N;i++)cout<<ans[i].first<<" "<<ans[i].second<<"\n";
	}
}
0