結果
問題 | No.738 平らな農地 |
ユーザー | fgwiebfaoish |
提出日時 | 2020-04-12 09:07:40 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 516 ms / 2,000 ms |
コード長 | 6,308 bytes |
コンパイル時間 | 1,985 ms |
コンパイル使用メモリ | 108,928 KB |
実行使用メモリ | 78,180 KB |
最終ジャッジ日時 | 2024-09-22 02:15:26 |
合計ジャッジ時間 | 23,264 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
17,664 KB |
testcase_01 | AC | 24 ms
18,176 KB |
testcase_02 | AC | 24 ms
17,920 KB |
testcase_03 | AC | 24 ms
17,920 KB |
testcase_04 | AC | 24 ms
18,048 KB |
testcase_05 | AC | 33 ms
19,464 KB |
testcase_06 | AC | 36 ms
19,480 KB |
testcase_07 | AC | 32 ms
19,228 KB |
testcase_08 | AC | 31 ms
18,944 KB |
testcase_09 | AC | 28 ms
18,688 KB |
testcase_10 | AC | 29 ms
18,432 KB |
testcase_11 | AC | 30 ms
19,200 KB |
testcase_12 | AC | 28 ms
18,688 KB |
testcase_13 | AC | 34 ms
19,712 KB |
testcase_14 | AC | 30 ms
18,688 KB |
testcase_15 | AC | 252 ms
72,612 KB |
testcase_16 | AC | 255 ms
73,408 KB |
testcase_17 | AC | 282 ms
73,076 KB |
testcase_18 | AC | 273 ms
68,084 KB |
testcase_19 | AC | 311 ms
76,272 KB |
testcase_20 | AC | 263 ms
73,540 KB |
testcase_21 | AC | 311 ms
76,264 KB |
testcase_22 | AC | 268 ms
73,740 KB |
testcase_23 | AC | 297 ms
74,496 KB |
testcase_24 | AC | 301 ms
74,096 KB |
testcase_25 | AC | 30 ms
18,816 KB |
testcase_26 | AC | 30 ms
18,944 KB |
testcase_27 | AC | 30 ms
18,944 KB |
testcase_28 | AC | 30 ms
18,944 KB |
testcase_29 | AC | 30 ms
18,944 KB |
testcase_30 | AC | 29 ms
19,200 KB |
testcase_31 | AC | 30 ms
19,072 KB |
testcase_32 | AC | 30 ms
18,816 KB |
testcase_33 | AC | 28 ms
18,944 KB |
testcase_34 | AC | 29 ms
19,072 KB |
testcase_35 | AC | 28 ms
18,944 KB |
testcase_36 | AC | 30 ms
18,944 KB |
testcase_37 | AC | 31 ms
19,200 KB |
testcase_38 | AC | 30 ms
18,944 KB |
testcase_39 | AC | 29 ms
18,652 KB |
testcase_40 | AC | 30 ms
18,944 KB |
testcase_41 | AC | 29 ms
18,816 KB |
testcase_42 | AC | 29 ms
19,072 KB |
testcase_43 | AC | 31 ms
18,944 KB |
testcase_44 | AC | 29 ms
19,072 KB |
testcase_45 | AC | 259 ms
77,728 KB |
testcase_46 | AC | 247 ms
72,548 KB |
testcase_47 | AC | 253 ms
75,980 KB |
testcase_48 | AC | 235 ms
73,596 KB |
testcase_49 | AC | 237 ms
73,072 KB |
testcase_50 | AC | 238 ms
75,588 KB |
testcase_51 | AC | 264 ms
76,224 KB |
testcase_52 | AC | 242 ms
72,944 KB |
testcase_53 | AC | 252 ms
74,164 KB |
testcase_54 | AC | 263 ms
76,356 KB |
testcase_55 | AC | 258 ms
71,820 KB |
testcase_56 | AC | 264 ms
75,216 KB |
testcase_57 | AC | 237 ms
72,128 KB |
testcase_58 | AC | 249 ms
74,680 KB |
testcase_59 | AC | 243 ms
77,856 KB |
testcase_60 | AC | 244 ms
77,108 KB |
testcase_61 | AC | 251 ms
76,588 KB |
testcase_62 | AC | 238 ms
72,428 KB |
testcase_63 | AC | 268 ms
77,724 KB |
testcase_64 | AC | 278 ms
76,596 KB |
testcase_65 | AC | 428 ms
73,476 KB |
testcase_66 | AC | 429 ms
75,252 KB |
testcase_67 | AC | 316 ms
73,360 KB |
testcase_68 | AC | 309 ms
75,220 KB |
testcase_69 | AC | 454 ms
75,972 KB |
testcase_70 | AC | 365 ms
77,968 KB |
testcase_71 | AC | 324 ms
74,344 KB |
testcase_72 | AC | 303 ms
74,536 KB |
testcase_73 | AC | 303 ms
74,456 KB |
testcase_74 | AC | 342 ms
76,084 KB |
testcase_75 | AC | 398 ms
72,864 KB |
testcase_76 | AC | 330 ms
75,332 KB |
testcase_77 | AC | 461 ms
73,100 KB |
testcase_78 | AC | 516 ms
77,976 KB |
testcase_79 | AC | 511 ms
78,132 KB |
testcase_80 | AC | 390 ms
75,884 KB |
testcase_81 | AC | 435 ms
73,864 KB |
testcase_82 | AC | 419 ms
76,240 KB |
testcase_83 | AC | 338 ms
78,180 KB |
testcase_84 | AC | 298 ms
76,140 KB |
testcase_85 | AC | 455 ms
77,716 KB |
testcase_86 | AC | 419 ms
72,768 KB |
testcase_87 | AC | 178 ms
75,092 KB |
testcase_88 | AC | 172 ms
73,032 KB |
testcase_89 | AC | 24 ms
17,920 KB |
testcase_90 | AC | 23 ms
18,048 KB |
testcase_91 | AC | 23 ms
17,792 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 s=sc.Ia; var a=sc.Ia; var wm=new Wm(a); long ans=long.MaxValue; for(int i = 0;i<=s[0]-s[1];i++) { long c=wm.Qt(i,i+s[1]-1,(s[1]+1)>>1); ans=Min(ans,c*wm.Rl(i,i+s[1]-1,c)-wm.Rls(i,i+s[1]-1,c)+wm.Rms(i,i+s[1]-1,c)-c*wm.Rm(i,i+s[1]-1,c)); } Console.WriteLine(ans); } } public class Wm{ private int[][] ra; private long[][] fa; private int[] za; private const int b=30; private int n; public Wm(int[] a){ n=a.Length; var d=new int[b+1][]; ra=new int[b+1][]; fa=new long[b+2][]; for(int i = 0;i<=b;i++) { d[i]=new int[n]; ra[i]=new int[n+1]; fa[i]=new long[n+1]; } fa[b+1]=new long[n+1]; var d0=new int[2][]{new int[n],new int[n]}; var d1=new int[2][]{new int[n],new int[n]}; var h0=new int[]{0,0}; var h1=new int[]{0,0}; za=new int[b+1]; for(int i = 0;i<n;i++) { if((a[i]&(1<<b))==0){ d0[1][h0[1]]=a[i]; h0[1]++; za[b]++; } else{ d1[1][h1[1]]=a[i]; h1[1]++; d[b][i]=ra[b][i+1]=1; } ra[b][i+1]+=ra[b][i]; fa[b+1][i+1]+=fa[b+1][i]+a[i]; } for(int i = 1;i<=b;i++) { int g=(1<<(b-i)),p=i&1; h0[p^1]=h1[p^1]=0; for(int j = 0;j<h0[p];j++) { if((d0[p][j]&g)==0){ d0[p^1][h0[p^1]]=d0[p][j]; h0[p^1]++; za[b-i]++; } else{ d1[p^1][h1[p^1]]=d0[p][j]; h1[p^1]++; d[b-i][j]=ra[b-i][j+1]=1; } ra[b-i][j+1]+=ra[b-i][j]; fa[b-i+1][j+1]+=fa[b-i+1][j]+d0[p][j]; } for(int j = 0;j<h1[p];j++) { if((d1[p][j]&g)==0){ d0[p^1][h0[p^1]]=d1[p][j]; h0[p^1]++; za[b-i]++; } else{ d1[p^1][h1[p^1]]=d1[p][j]; h1[p^1]++; d[b-i][h0[p]+j]=ra[b-i][h0[p]+j+1]=1; } ra[b-i][h0[p]+j+1]+=ra[b-i][h0[p]+j]; fa[b-i+1][h0[p]+j+1]+=fa[b-i+1][h0[p]+j]+d1[p][j]; } } int v=(b&1)^1; for(int j = 0;j<h0[v];j++) {fa[0][j+1]+=fa[0][j]+d0[v][j];} for(int j = 0;j<h1[v];j++) {fa[0][h0[v]+j+1]+=fa[0][h0[v]+j]+d1[v][j];} } public int Rk(int l,int r,long k){ l--; for(int i = b;i>=0;i--) { if(((k>>i)&1)==1){ r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; } else{ r=r-ra[i][r+1]; l=l-ra[i][l+1]; } } return r-l; } public int Rl(int l,int r,long k){ l--; int p=0; for(int i = b;i>=0;i--) { if(((k>>i)&1)==1){ p+=r-l; r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; p-=r-l; } else{ r=r-ra[i][r+1]; l=l-ra[i][l+1]; } } return p; } public int Rm(int l,int r,long k){ l--; int p=0; for(int i = b;i>=0;i--) { if(((k>>i)&1)==1){ r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; } else{ p+=r-l; r=r-ra[i][r+1]; l=l-ra[i][l+1]; p-=r-l; } } return p; } public long Rls(int l,int r,long k){ l--; long p=0; for(int i = b;i>=0;i--) { if(((k>>i)&1)==1){ p+=fa[i+1][r+1]-fa[i+1][l+1]; r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; p-=fa[i][r+1]-fa[i][l+1]; } else{ r=r-ra[i][r+1]; l=l-ra[i][l+1]; } } return p; } public long Rms(int l,int r,long k){ l--; long p=0; for(int i = b;i>=0;i--) { if(((k>>i)&1)==1){ r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; } else{ p+=fa[i+1][r+1]-fa[i+1][l+1]; r=r-ra[i][r+1]; l=l-ra[i][l+1]; p-=fa[i][r+1]-fa[i][l+1]; } } return p; } public int Qt(int l,int r,int k){ l--; int p=0; for(int i = b;i>=0;i--) { if((r-ra[i][r+1])-(l-ra[i][l+1])<k){ k-=(r-ra[i][r+1])-(l-ra[i][l+1]); r=ra[i][r+1]+za[i]-1; l=ra[i][l+1]+za[i]-1; p|=1<<i; } else{ r=r-ra[i][r+1]; l=l-ra[i][l+1]; } } return p; } public int Pv(int l,int r,int k){ int p=Rl(l,r,k); return p!=0?Qt(l,r,p):-1; } public int Nv(int l,int r,int k){ int p=Rm(l,r,k); return p!=0?Qt(l,r,r-l+1-p+1):-1; } } 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(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);} public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);} public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}} public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);} public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);} public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}} public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);} public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).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;} }