結果
問題 | No.1 道のショートカット |
ユーザー |
|
提出日時 | 2025-01-07 08:25:35 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 70 ms / 5,000 ms |
コード長 | 4,596 bytes |
コンパイル時間 | 14,859 ms |
コンパイル使用メモリ | 172,856 KB |
実行使用メモリ | 193,992 KB |
最終ジャッジ日時 | 2025-01-07 08:25:54 |
合計ジャッジ時間 | 18,760 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (102 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;using System.Linq;using System.Numerics;using System.Collections.Generic;using System.IO;using System.Text;using N = System.Int32;public class Solver{public void Solve(){int N = ri, C = ri, V = ri;int[] S = new int[V];int[] T = new int[V];int[] Y = new int[V];int[] M = new int[V];for(int i = 0; i < V; ++i){S[i] = ri - 1;}for(int i = 0; i < V; ++i){T[i] = ri - 1;}for(int j = 0; j < V; ++j){Y[j] = ri;}for(int j = 0; j < V; ++j){M[j] = ri;}long [,] dp = new long[N, C + 1];for(int i = 0; i < N; ++i){for(int j = 0; j <= C; ++j){dp[i, j] = mod;}}var G = new Dictionary<int, List<int>>();for(int i = 0; i < N; ++i){G[i] = new List<int>();}for(int i = 0; i < V; ++i){G[S[i]].Add(i);}dp[0, 0] = 0;for(int i = 0; i < N; ++i){for(int j = 0; j <= C; ++j){if(dp[i, j] == mod) continue;foreach(int k in G[i]){if(j + Y[k] > C) continue;dp[T[k], j + Y[k]] = Math.Min(dp[T[k], j + Y[k]], dp[i, j] + M[k]);}}}long ans = mod;for(int i = 0; i <= C; ++i){ans = Math.Min(ans, dp[N - 1, i]);}if(ans == mod) ans = -1;Write(ans);}int ri { get { return sc.Integer(); } }long rl { get { return sc.Long(); } }double rd { get { return sc.Double(); } }string rs { get { return sc.Scan(); } }public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());private const N mod = 1000000007;N Reverse(N n) { return Pow(n, mod - 2); }N Mul(params N[] n) { N p = n[0]; for (N i = 1; i < n.Length; i++) { p = (p * n[i]) % mod; } return p; }N Pow(N n, N p) { N t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p >>= 1; } return q; }N PowUpper(N n, N b) { N p = 1; while (p <= n) { p *= b; } return p; }N Sign(N n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }N Abs(N n) { return (n > 0) ? n : -n; }N Gcd(params N[] n) { N p = n[0]; for (N i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; }N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }N Lcm(params N[] n) { N p = n[0]; for (N i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; }N Lcm(N a, N b) { return (a / Gcd(a, b) * b) % mod; }void Write<T>(T t) { Console.WriteLine(t.ToString()); }void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }}static class Program{static public void Main(string[] args){Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });var solver = new Solver();solver.Solve();Console.Out.Flush();}}public class StreamScanner{public StreamScanner(Stream stream) { str = stream; }private readonly Stream str;private readonly byte[] buf = new byte[1024];private int len, ptr;public bool isEof = false;public bool IsEndOfStream { get { return isEof; } }private byte read(){if (isEof) throw new EndOfStreamException();if (ptr >= len){ptr = 0;if ((len = str.Read(buf, 0, 1024)) <= 0){isEof = true;return 0;}}return buf[ptr++];}public char Char(){byte b = 0;do b = read();while (b < 33 || 126 < b);return (char)b;}public string Scan(){var sb = new StringBuilder();for (var b = Char(); b >= 33 && b <= 126; b = (char)read())sb.Append(b);return sb.ToString();}public long Long(){long ret = 0; byte b = 0; var ng = false;do b = read();while (b != '-' && (b < '0' || '9' < b));if (b == '-') { ng = true; b = read(); }for (; true; b = read()){if (b < '0' || '9' < b)return ng ? -ret : ret;else ret = ret * 10 + b - '0';}}public int Integer() { return (int)Long(); }public double Double() { return double.Parse(Scan()); }}