結果
| 問題 | No.602 隠されていたゲーム2 |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-11-03 15:54:54 |
| 言語 | C# (.NET 10.0.403 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 88 ms / 2,000 ms |
| + 623µs | |
| コード長 | 2,373 bytes |
| 記録 | |
| コンパイル時間 | 13,761 ms |
| コンパイル使用メモリ | 173,096 KB |
| 実行使用メモリ | 48,512 KB |
| 最終ジャッジ日時 | 2026-11-03 15:55:12 |
| 合計ジャッジ時間 | 11,926 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (196 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net10.0/main.dll main -> /home/judge/data/code/bin/Release/net10.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
static int NN => int.Parse(ReadLine());
static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var n = NN;
var d = NList;
var c = NList;
WriteLine(Game(n, d, Math.Abs(c[0]) + Math.Abs(c[1])));
}
static int Game(int n, int[] d, long x)
{
if (x == 0)
{
return 0;
}
var emax = -1;
var omax = -1;
var elist = new List<long>();
var olist = new List<long>();
foreach (var di in d)
{
if (x == di)
{
return 1;
}
if (di % 2 == 0)
{
emax = Math.Max(emax, di * 2);
elist.Add(di);
}
else
{
omax = Math.Max(omax, di * 2);
olist.Add(di);
}
}
if (x % 2 == 0) return x <= emax || x <= omax ? 2 : -1;
else
{
if (elist.Count == 0 || olist.Count == 0)
{
return -1;
}
elist.Sort();
olist.Sort();
foreach (var e in elist)
{
var opos = Math.Max(LowerBound(0, e, olist), LowerBound(0, x - e, olist));
if (opos < olist.Count && olist[opos] <= x + e)
{
return 2;
}
}
foreach (var o in olist)
{
var epos = Math.Max(LowerBound(0, o, elist), LowerBound(0, x - o, elist));
if (epos < elist.Count && elist[epos] <= x + o)
{
return 2;
}
}
return -1;
}
}
static int LowerBound(int left, long min, IList<long> list)
{
if (list[left] >= min) return left;
var ng = left;
var ok = list.Count;
while (ok - ng > 1)
{
var mid = (ng + ok) / 2;
if (list[mid] < min) ng = mid;
else ok = mid;
}
return ok;
}
}