結果
| 問題 |
No.519 アイドルユニット
|
| コンテスト | |
| ユーザー |
yuya178
|
| 提出日時 | 2017-06-16 00:30:13 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,951 bytes |
| コンパイル時間 | 2,118 ms |
| コンパイル使用メモリ | 78,244 KB |
| 実行使用メモリ | 130,276 KB |
| 最終ジャッジ日時 | 2024-09-25 03:14:37 |
| 合計ジャッジ時間 | 6,790 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 33 |
ソースコード
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int N = in.nextInt();
int arr[][] = new int[N+1][N+1];
int ans;
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++){
arr[i][j] = in.nextInt();
}
}
int num[] = new int[N+1];
for(int i=1; i<=N; i++){
num[i] = i;
}
ans = pair(num,arr,N);
out.println(ans);
}
private static int pair(int num[], int arr[][],int N){
int res=0;
int max=0;
int start=1;
int copy[] = new int[N+1];
Arrays.sort(num);
if(num[N]==0) return 0;
for(int i=1; i<=N; i++){
if(num[i]!=0){
start=i;
break;
}
}
for(int i=1; start+i<=N; i++){
for(int j=1; j<=N; j++){
copy[j] = num[j];
}
copy[start]=0;
copy[start+i]=0;
res = arr[num[start]][num[start+i]]+pair(copy,arr,N);
if(res>max){
max=res;
}
}
return max;
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
yuya178