結果
| 問題 |
No.2232 Miser's Gift
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-25 07:09:49 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,440 bytes |
| コンパイル時間 | 3,510 ms |
| コンパイル使用メモリ | 114,448 KB |
| 実行使用メモリ | 78,280 KB |
| 最終ジャッジ日時 | 2024-10-02 01:39:40 |
| 合計ジャッジ時間 | 8,964 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 3 OLE * 7 -- * 45 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
public static void Main()
{
Solve();
}
static void Solve()
{
var c = NList;
var (n, w) = (c[0], c[1]);
var map = NArr(n);
var INF = int.MinValue;
var init = Enumerable.Repeat(INF, w + 1).ToArray();
var dp = (int[]) init.Clone();
dp[0] = 0;
for (var i = 0; i < n; ++i)
{
var ndp = (int[]) dp.Clone();
for (var j = 0; j < dp.Length; ++j)
{
if (j + map[i][0] >= ndp.Length) break;
ndp[j + map[i][0]] = Math.Max(ndp[j + map[i][0]], dp[j] + map[i][1]);
}
dp = ndp;
WriteLine(string.Join(" ", dp));
}
var ans = new int[w];
for (var i = 0; i < ans.Length; ++i) ans[i] = dp[w] - dp[w - i - 1] + 1;
WriteLine(string.Join("\n", ans.Select(ai => ai < 0 ? 1 : ai)));
}
static long Exp(int n, int k, int mod)
{
if (k == 0) return 1;
if (k == 1) return n % mod;
var half = Exp(n, k / 2, mod);
var result = (half * half) % mod;
return ((k % 2) == 0) ? result : ((result * n) % mod);
}
class UnionFindTree
{
int[] roots;
public UnionFindTree(int size)
{
roots = new int[size];
for (var i = 0; i < size; ++i) roots[i] = -1;
}
public int GetRoot(int a)
{
if (roots[a] < 0) return a;
return roots[a] = GetRoot(roots[a]);
}
public bool IsSameTree(int a, int b)
{
return GetRoot(a) == GetRoot(b);
}
public bool Unite(int a, int b)
{
var x = GetRoot(a);
var y = GetRoot(b);
if (x == y) return false;
if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; }
roots[x] += roots[y];
roots[y] = x;
return true;
}
public int GetSize(int a)
{
return -roots[GetRoot(a)];
}
}
}