結果
| 問題 |
No.5020 Averaging
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-25 16:57:05 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 884 ms / 1,000 ms |
| コード長 | 4,425 bytes |
| コンパイル時間 | 7,335 ms |
| コンパイル使用メモリ | 156,108 KB |
| 実行使用メモリ | 204,236 KB |
| スコア | 29,691,924 |
| 最終ジャッジ日時 | 2024-02-25 16:58:21 |
| 合計ジャッジ時間 | 54,714 ms |
|
ジャッジサーバーID (参考情報) |
judge10 / judge13 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 50 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (100 ms)。 MSBuild のバージョン 17.7.3+8ec440e68 (.NET) main -> /home/judge/data/code/bin/Release/net7.0/main.dll main -> /home/judge/data/code/bin/Release/net7.0/publish/
ソースコード
using System;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Reflection;
class Program
{
static void Main()
{
int n = ni();
long[][] co = nml(n);
long O = 500000000000000000L;
List<int[]> ret = new List<int[]>();
long lmin = O*2;
int argmin = -1;
for(int i = 0;i < n;i++){
long x = (co[0][0] + co[i][0]) / 2;
long y = (co[0][1] + co[i][1]) / 2;
long d = Math.Abs(x - O) + Math.Abs(y - O);
if(d < lmin){
lmin = d;
argmin = i;
}
}
if(argmin > 0){
long xx = (co[0][0] + co[argmin][0]) / 2;
long yy = (co[0][1] + co[argmin][1]) / 2;
co[0][0] = co[argmin][0] = xx;
co[0][1] = co[argmin][1] = yy;
ret.Add(new int[]{0, argmin});
}
long tx = O*2 - co[0][0];
long ty = O*2 - co[0][1];
long[][] cco = co.Skip(1).ToArray();
long[] last = new long[0];
Random gen = new Random();
int ct = 0;
for(int rep = 0;rep < 16;rep++){
double best = Double.PositiveInfinity;
long[][] barg = new long[4][];
Stopwatch sw = Stopwatch.StartNew();
while(sw.ElapsedMilliseconds < 50){
bool[] used = new bool[cco.Length];
long[][] sel = new long[4][];
for(int i = 0;i < 4;i++){
while(true){
int t = (int)(gen.NextInt64() % cco.Length);
if(used[t])continue;
sel[i] = cco[t];
used[t] = true;
break;
}
}
// long[][] sel = cco.OrderBy(x => gen.Next()).Take(4).ToArray();
double x = 0, y = 0;
for(int i = 0;i < 4;i++){
x += sel[i][0];
y += sel[i][1];
}
x /= 4;
y /= 4;
double d = Math.Max(Math.Abs(x - tx), Math.Abs(y - ty));
if(d < best){
best = d;
barg = sel;
}
ct++;
}
for(int d = 1;d <= 2;d*=2){
for(int i = 0;i < 4;i+=d*2){
long x = (barg[i][0] + barg[i+d][0]) / 2;
long y = (barg[i][1] + barg[i+d][1]) / 2;
barg[i][0] = barg[i+d][0] = x;
barg[i][1] = barg[i+d][1] = y;
ret.Add(new int[]{(int)barg[i][2], (int)barg[i+d][2]});
}
}
last = barg[0];
}
// Console.WriteLine($"arg {arg} {vald}");
ret.Add(new int[]{0, (int)last[2]});
Console.WriteLine(ret.Count);
foreach(int[] r in ret){
Console.WriteLine($"{r[0]+1} {r[1]+1}");
}
// Console.WriteLine(ct);
// long lx = (co[0][0] + last[0]) / 2;
// long ly = (co[0][1] + last[1]) / 2;
// Console.WriteLine($"last: {lx} {ly}");
}
static double min;
static List<int> best = new List<int>();
static void simulate(double[] a, int rem, List<int> route)
{
for(int i = 0;i < 4;i++){
if(Math.Abs(a[i]) < min){
min = Math.Abs(a[i]);
best = new List<int>(route);
}
}
if(rem == 0)return;
for(int i = 0;i < 3;i++){
if(a[i] == a[i+1])continue;
double[] b = (double[])a.Clone();
double v = (b[i] + b[i+1]) / 2;
b[i] = b[i+1] = v;
route.Add(i);
simulate(b, rem-1, route);
route.RemoveAt(route.Count-1);
}
}
static string ns()
{
return Console.ReadLine();
}
static int ni()
{
return Convert.ToInt32(ns());
}
static int[] na()
{
return ns().Split(' ').Select(int.Parse).ToArray();
}
static long[] nal()
{
return ns().Split(' ').Select(long.Parse).ToArray();
}
static long[][] nml(int n)
{
long[][] ret = new long[n][];
for (int i = 0; i < n; i++)
{
long[] f = nal();
ret[i] = new long[]{f[0], f[1], i};
}
return ret;
}
}