結果
| 問題 | No.90 品物の並び替え |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-07 19:42:39 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,169 bytes |
| 記録 | |
| コンパイル時間 | 30 ms |
| 最終ジャッジ日時 | 2026-03-04 21:47:30 |
| 合計ジャッジ時間 | 291 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
d869be5ea8ee
[/j_bin/judge_tool judge 40000 CompileMemory.txt /dev/null sud /dev/null _ python3 java_util.py code Main.java java]
strconv.Atoi: parsing "CompileMemory.txt": invalid syntax
goroutine 1 [running]:
runtime/debug.Stack()
/home/yuki2006/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/src/runtime/debug/stack.go:26 +0x5e
main.main.func1()
/home/yuki2006/gopath/src/yukicoder/judge/main.go:22 +0x57
panic({0x7d6880?, 0xc0000f6210?})
/home/yuki2006/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.linux-amd64/src/runtime/panic.go:783 +0x132
main.judgeMain({0xc000012100, 0x5?, 0x0?})
/home/yuki2006/gopath/src/yukicoder/judge/judge_linux.go:121 +0x4b1
main.main()
/home/yuki2006/gopath/src/yukicoder/judge/main.go:97 +0x277
ソースコード
import java.util.*;
import java.lang.Math;
public class ppp {
public static void main(String[] args) {
MyScanner sc=new MyScanner();
int n=sc.nextInt();
int m=sc.nextInt();
int item1[]=new int[m];
int item2[]=new int[m];
int score[]=new int[m];
for(int i=0;i<m;i++){
item1[i]=sc.nextInt();
item2[i]=sc.nextInt();
score[i]=sc.nextInt();
}
int k=1;
int N=n;
while(N>0){
k*=N;
N--;
}
int b[]=new int[n];
int ans=0;
for(int i=0;i<n;i++){
b[i]=i;
}
for(int i=0;i<k;i++){
int a[]=permutation(b,i,k);
int s=0;
for(int j=0;j<m;j++){
int x=0;
int y=0;
for(int p=0;p<n;p++){
if(a[p]==item1[j])x=p;
if(a[p]==item2[j])y=p;
}
if(x<y)s+=score[j];
}
ans=Math.max(ans,s);
}
System.out.println(ans);
}
static int[] permutation(int[] base, int x,int k) {
int n = base.length;
int ans[] = new int[n];
if (n == 1)
return base;
else {
ArrayList<Integer> B = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
B.add(base[i]);
}
k /= n;
int N = n - 1;
for (int i = 0; i < n - 1; i++) {
ans[i] = B.get(x / k);
B.remove(x / k);
x %= k;
k /= N;
N--;
}
ans[n - 1] = B.get(0);
}
return ans;
}
}
class MyScanner {
int nextInt() {
try {
int c = System.in.read();
while (c != '-' && (c < '0' || '9' < c))
c = System.in.read();
if (c == '-')
return -nextInt();
int res = 0;
do {
res *= 10;
res += c - '0';
c = System.in.read();
} while ('0' <= c && c <= '9');
return res;
} catch (Exception e) {
return -1;
}
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String next() {
try {
StringBuilder res = new StringBuilder("");
int c = System.in.read();
while (Character.isWhitespace(c))
c = System.in.read();
do {
res.append((char) c);
} while (!Character.isWhitespace(c = System.in.read()));
return res.toString();
} catch (Exception e) {
return null;
}
}
}