結果

問題 No.4 おもりと天秤
ユーザー nokonoko
提出日時 2025-09-24 06:35:32
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 2,351 bytes
コンパイル時間 17,107 ms
コンパイル使用メモリ 173,668 KB
実行使用メモリ 189,156 KB
最終ジャッジ日時 2025-09-24 06:35:52
合計ジャッジ時間 11,019 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (121 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using STR = System.String;
using INT = System.Int64;
using DEC = System.Double;
using BOOL = System.Boolean;
class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        INT n = IO.I();
        INT[] w = IO.I(' ');
        INT total = w.Sum();
        BOOL[,] dp = new BOOL[n + 1, 10001];
        dp[0, 0] = true;
        if (total % 2 == 0)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < 10001; j++)
                {
                    if (dp[i, j])
                    {
                        dp[i + 1, j + w[i]] = true;
                        dp[i + 1, j] = true;
                    }
                }
            }
        }
        IO.W(dp[n, total / 2] ? "possible" : "impossible");
        IO.F();
    }
}
public class IO
{
    private const int WMAX = 1000;
    private StringBuilder SB = new StringBuilder();
    private T R<T>(Func<STR, T> f) { return f(Console.ReadLine()); }
    private T[] R<T>(Func<STR, T> f, char c) { return S().Split(c).Select(f).ToArray(); }
    private T[] R<T>(Func<STR, T> f, INT l) { T[] r = new T[l]; for (INT i = 0; i < l; i++) { r[i] = R(f); } return r; }
    private T[][] R<T>(Func<STR, T> f, INT l, char c) { T[][] r = new T[l][]; for (INT i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
    private void W<T>(Func<T, STR> f, T v, bool lf = true) { SB.Append(f(v)); if (lf) { SB.Append('\n'); } if (SB.Length >= WMAX) { F(); } }
    public STR S() { return R(s => s); }
    public STR[] S(char c) { return R(s => s, c); }
    public STR[] S(INT l) { return R(s => s, l); }
    public STR[][] S(INT l, char c) { return R(s => s, l, c); }
    public INT I() { return R(INT.Parse); }
    public INT[] I(char c) { return R(INT.Parse, c); }
    public INT[] I(INT l) { return R(INT.Parse, l); }
    public INT[][] I(INT l, char c) { return R(INT.Parse, l, c); }
    public DEC D() { return R(DEC.Parse); }
    public DEC[] D(char c) { return R(DEC.Parse, c); }
    public DEC[] D(INT l) { return R(DEC.Parse, l); }
    public DEC[][] D(INT l, char c) { return R(DEC.Parse, l, c); }
    public void W(object s, bool lf = true) { W(v => v.ToString(), s, lf); }
    public void F() { Console.Write(SB); SB.Length = 0; }
}
0