結果
| 問題 |
No.3325 陰陽師
|
| コンテスト | |
| ユーザー |
鳩でもわかるC#
|
| 提出日時 | 2025-11-02 20:29:00 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 1,476 ms / 2,000 ms |
| コード長 | 4,920 bytes |
| コンパイル時間 | 7,325 ms |
| コンパイル使用メモリ | 168,400 KB |
| 実行使用メモリ | 189,648 KB |
| 最終ジャッジ日時 | 2025-11-02 20:29:42 |
| 合計ジャッジ時間 | 37,531 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (101 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using AtCoder;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
class Program
{
static string ReadLine() => Console.ReadLine().Trim();
static int ReadInt() => int.Parse(ReadLine());
static long ReadLong() => long.Parse(ReadLine());
static int[] ReadIntArray() { string str = ReadLine(); return str != "" ? str.Split().Select(_ => int.Parse(_)).ToArray() : new int[0]; }
static long[] ReadLongArray() { string str = ReadLine(); return str != "" ? str.Split().Select(_ => long.Parse(_)).ToArray() : new long[0]; }
static (int a, int b) ReadInt2() { int[] vs = ReadIntArray(); return (a: vs[0], b: vs[1]); }
static (int a, int b, int c) ReadInt3() { int[] vs = ReadIntArray(); return (a: vs[0], b: vs[1], c: vs[2]); }
static (int a, int b, int c, int d) ReadInt4() { int[] vs = ReadIntArray(); return (a: vs[0], b: vs[1], c: vs[2], d: vs[3]); }
static (long a, long b) ReadLong2() { long[] vs = ReadLongArray(); return (a: vs[0], b: vs[1]); }
static (long a, long b, long c) ReadLong3() { long[] vs = ReadLongArray(); return (a: vs[0], b: vs[1], c: vs[2]); }
static (long a, long b, long c, long d) ReadLong4() { long[] vs = ReadLongArray(); return (a: vs[0], b: vs[1], c: vs[2], d: vs[3]); }
static void Main()
{
SourceExpander.Expander.Expand();
(int N, int M) = ReadInt2();
int[] S = ReadIntArray().OrderBy(_ => _).ToArray();
int[] T = ReadIntArray();
int ok = 0;
int ng = T.Length + 1;
int cnt = StlFunction.BinarySearch(ok, ng, mid => Check(mid));
Console.WriteLine(GetScore(cnt));
bool Check(int cnt)
{
int[] T2 = T.Take(cnt).OrderBy(_ => _).ToArray();
Queue<int> q = new Queue<int>(S);
foreach (int v in T2)
{
while (q.Count > 0 && q.Peek() < v)
q.Dequeue();
if (q.Count > 0)
q.Dequeue();
else
return false;
}
return true;
}
long GetScore(int cnt)
{
long ans = 0;
int[] T2 = T.Take(cnt).OrderBy(_ => _).ToArray();
Queue<int> q = new Queue<int>(S);
foreach (int v in T2)
{
while (q.Count > 0 && q.Peek() < v)
q.Dequeue();
if (q.Count > 0)
{
int d = q.Dequeue();
ans = Math.Max(ans, d - v);
}
else
return 0;
}
return ans;
}
}
}
#region Expanded by https://github.com/kzrnm/SourceExpander
namespace AtCoder{public static class StlFunction{public struct NextPermutationEnumerator<T>:IEnumerator<T[]>,IEnumerable<T[]>where T:IComparable<T>{internal readonly IEnumerable<T>_orig;internal NextPermutationEnumerator(IEnumerable<T>orig){_orig=orig;Current=null;}public T[]Current{get;private set;}[MethodImpl(256)]public bool MoveNext(){if(Current==null){Current=_orig.ToArray();return true;}return NextPermutation(Current);}public void Reset()=>Current=null;object IEnumerator.Current=>Current;void IDisposable.Dispose(){}[MethodImpl(256)]public NextPermutationEnumerator<T>GetEnumerator()=>this;IEnumerator<T[]>IEnumerable<T[]>.GetEnumerator()=>this;IEnumerator IEnumerable.GetEnumerator()=>this;}[MethodImpl(256)]public static bool NextPermutation<T>(T[]array)where T:IComparable<T> =>NextPermutation(array.AsSpan());[MethodImpl(256)]public static bool NextPermutation<T>(Span<T>span)where T:IComparable<T>{int i;for(i=span.Length-2;i>=0;i--)if(span[i].CompareTo(span[i+1])<0)break;if(i<0)return false;int j;for(j=span.Length-1;j>=0;j--)if(span[i].CompareTo(span[j])<0)break;(span[i],span[j])=(span[j],span[i]);span.Slice(i+1,span.Length-i-1).Reverse();return true;}[MethodImpl(256)]public static NextPermutationEnumerator<T>Permutations<T>(IEnumerable<T>orig)where T:IComparable<T> =>new NextPermutationEnumerator<T>(orig);private struct DefaultComparer<T>:IComparer<T>where T:IComparable<T>{[MethodImpl(256)]public int Compare(T x,T y)=>x.CompareTo(y);}[MethodImpl(256)]public static int BinarySearch(int ok,int ng,Predicate<int>Ok){while(Math.Abs(ok-ng)>1){var m=(ok+ng)>>1;if(Ok(m))ok=m;else ng=m;}return ok;}[MethodImpl(256)]public static long BinarySearch(long ok,long ng,Predicate<long>Ok){while(Math.Abs(ok-ng)>1){var m=(ok+ng)>>1;if(Ok(m))ok=m;else ng=m;}return ok;}}}
namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}}
#endregion Expanded by https://github.com/kzrnm/SourceExpander
鳩でもわかるC#