結果
| 問題 |
No.115 遠足のおやつ
|
| コンテスト | |
| ユーザー |
kuuso1
|
| 提出日時 | 2014-12-29 00:54:32 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,042 bytes |
| コンパイル時間 | 2,641 ms |
| コンパイル使用メモリ | 106,880 KB |
| 実行使用メモリ | 22,272 KB |
| 最終ジャッジ日時 | 2024-11-07 17:13:56 |
| 合計ジャッジ時間 | 17,333 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 TLE * 1 |
コンパイルメッセージ
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;
using System.Collections.Generic;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
dp=new int[D+1][];
for(int i=0;i<D+1;i++){
dp[i]=new int[K+1];
}
dp[0][0]=1;
for(int i=1;i<=N;i++){
for(int k=K-1;k>=0;k--){
for(int d=D;d>=0;d--){
if(dp[d][k]==0)continue;
if(d+i<=D){
dp[d+i][k+1]=1;
}
}
}
}
if(dp[D][K]==0){
Console.WriteLine(-1);
return;
}
int[] r=new int[K];
for(int i=0;i<K;i++)r[i]=-1;
found=false;
for(int i=1;i<=N;i++){
r[0]=i;
dfs(r,D-i,K-1);
}
for(int i=0;i<K;i++){
Console.Write(i==0?"{0}":" {0}",route[i]);
}
Console.WriteLine();
}
int[][] dp;
bool found;
int[] route;
void dfs(int[] r_,int d_,int k_){
//for(int i=0;i<K;i++)Console.Write("{0} ",r_[i]);Console.WriteLine("d_={0},k_={1}",d_,k_);
if(found)return;
int[] r=(int[])r_.Clone();
int[] used=new int[N+1];
int now=-1;
for(int i=0;i<r.Length;i++){
if(r[i]!=-1){
now=i;
used[r[i]]=1;
}
}
if(now==r.Length-1){
if(d_==0 && k_==0){
route=new int[K];
for(int i=0;i<K;i++)route[i]=r[i];
found=true;
}
return;
}
for(int i=1;i<=N;i++){
if(d_-i>=0 && dp[d_-i][k_-1]==1 && used[i]!=1){
r[now+1]=i;
dfs(r,d_-i,k_-1);
}
}
}
int N,D,K;
public Sol(){
var d=ria();
N=d[0];D=d[1];K=d[2];
}
static String rs(){return Console.ReadLine();}
static int ri(){return int.Parse(Console.ReadLine());}
static long rl(){return long.Parse(Console.ReadLine());}
static double rd(){return double.Parse(Console.ReadLine());}
static String[] rsa(){return Console.ReadLine().Split(' ');}
static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
kuuso1