結果

問題 No.130 XOR Minimax
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-07-27 15:53:44
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 5,068 bytes
コンパイル時間 3,943 ms
コンパイル使用メモリ 111,868 KB
実行使用メモリ 160,932 KB
最終ジャッジ日時 2023-09-11 05:54:21
合計ジャッジ時間 50,872 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1,863 ms
24,424 KB
testcase_02 AC 1,862 ms
24,624 KB
testcase_03 AC 1,863 ms
24,500 KB
testcase_04 AC 1,865 ms
29,060 KB
testcase_05 AC 1,862 ms
39,096 KB
testcase_06 AC 1,867 ms
54,784 KB
testcase_07 WA -
testcase_08 AC 1,898 ms
160,932 KB
testcase_09 AC 1,862 ms
31,056 KB
testcase_10 AC 1,862 ms
35,608 KB
testcase_11 AC 1,866 ms
47,236 KB
testcase_12 AC 1,864 ms
26,900 KB
testcase_13 AC 1,863 ms
44,408 KB
testcase_14 AC 1,888 ms
137,560 KB
testcase_15 AC 1,865 ms
26,752 KB
testcase_16 AC 1,881 ms
107,288 KB
testcase_17 AC 1,891 ms
109,368 KB
testcase_18 AC 1,884 ms
113,420 KB
testcase_19 AC 1,889 ms
131,432 KB
testcase_20 AC 1,874 ms
77,140 KB
testcase_21 AC 1,890 ms
133,656 KB
testcase_22 AC 1,868 ms
56,080 KB
testcase_23 AC 1,860 ms
34,908 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		DateTime st=DateTime.Now;
		var a=sc.Ia;
		var bt=new Bt();
		for(int i = 0;i<n;i++) {bt.Add(a[i]);}
		int x=0,m=a.Max();
		long p=bt.Ra(n),ans=p;
		const int t=1785;
		Random r=new Random(1);
		var dd=(DateTime.Now-st).TotalMilliseconds;
		while(dd<1800){
			var tp=t-dd+30;
			for(int i = 0;1<<i<=m;i++) {
				var g=bt.Ra(n,x^(1<<i));
				if(p>g||r.Next(1000000000)<Exp((p-g)/tp)*1000000000){
					p=g;
					x^=1<<i;
					ans=Min(ans,p);
				}
			}
			dd=(DateTime.Now-st).TotalMilliseconds;
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Bt{
	private const int b=30;
	private Nd r;
	public class Nd{
		public int d;
		public long n;
		public Nd[] h=new Nd[2];
		public override string ToString()=>"n:"+n.ToString()+" d:"+d.ToString();
	}
	public Bt(){r=new Nd();}
	public void Add(long n){
		var t=r;
		t.d++;
		for(int i = b;i>=0;i--) {
			long k=(n>>i)&1;
			t=t.h[k]==null?t.h[k]=new Nd():t.h[k];
			t.d++;
		}
		t.n=n;
	}
	public void Dl(long n){
		var t=r;
		t.d--;
		for(int i = b;i>=0;i--) {
			t=t.h[(n>>i)&1];
			t.d--;
		}
	}
	public long Ra(int n){
		if(n>r.d||n<1){return -1;}
		var t=r;
		for(int i = b;i>=0;i--) {
			if(t.h[0]==null){t=t.h[1];}
			else if(t.h[0].d<n){n-=t.h[0].d;t=t.h[1];}
			else{t=t.h[0];}
		}
		return t.n;
	}
	public long Ra(int n,int x){
		if(n>r.d||n<1){return -1;}
		var t=r;
		for(int i = b;i>=0;i--) {
			int k=(x>>i)&1;
			if(t.h[k]==null){t=t.h[k^1];}
			else if(t.h[k].d<n){n-=t.h[k].d;t=t.h[k^1];}
			else{t=t.h[k];}
		}
		return t.n^x;
	}
	public long Lb(long n){return Flb(r,n,b,1);}
	private long Flb(Nd t,long n,int b,int o){
		if(b==-1){return t.d!=0?t.n:-1;}
		int k=(int)((n>>b)&o);
		if(t.h[k]!=null&&t.h[k].d!=0){
			var p=Flb(t.h[k],n,b-1,o);
			if(p!=-1){return p;}
		}
		if(k==0&&t.h[1]!=null&&t.h[1].d!=0){return Flb(t.h[1],n,b-1,0);}
		return -1;
	}
	public long Ub(long n){return Fub(r,n,b,0);}
	private long Fub(Nd t,long n,int b,int o){
		if(b==-1){return t.d!=0?t.n:-1;}
		int k=((int)((n>>b)&1))|o;
		if(t.h[k]!=null&&t.h[k].d!=0){
			var p=Fub(t.h[k],n,b-1,o);
			if(p!=-1){return p;}
		}
		if(k==1&&t.h[0]!=null&&t.h[0].d!=0){return Fub(t.h[0],n,b-1,1);}
		return -1;
	}
	public long Max(){
		var t=r;
		for(int i = b;i>=0;i--) {t=t.h[1]!=null&&t.h[1].d!=0?t.h[1]:t.h[0];}
		return t.n;
	}
	public long Min(){
		var t=r;
		for(int i = b;i>=0;i--) {t=t.h[0]!=null&&t.h[0].d!=0?t.h[0]:t.h[1];}
		return t.n;
	}
	public long Max(long x){
		var t=r;
		for(int i = b;i>=0;i--) {
			int k=(int)(((x>>i)^1)&1);
			t=t.h[k]!=null&&t.h[k].d!=0?t.h[k]:t.h[k^1];
		}
		return t.n^x;
	}
	public long Min(long x){
		var t=r;
		for(int i = b;i>=0;i--) {
			int k=(int)(((x>>i)^1)&1)^1;
			t=t.h[k]!=null&&t.h[k].d!=0?t.h[k]:t.h[k^1];
		}
		return t.n^x;
	}
	public int cnt{get{return r.d;}}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0