답안 #134658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134658 2019-07-23T06:38:57 Z 이온조(#3239) Telegraph (JOI16_telegraph) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1LL * 1e18;
long long P[100009], D[100009];
int N, A[100009], C[100009], s;

void go(int x, int msk) {
	if(msk == (1 << N) - 1 && A[x] == s) {
		puts("0");
		exit(0);
	}
	P[msk] = C[x];
	if(msk & (1 << (A[x]-1))) return;
	go(A[x], msk | (1 << (A[x]-1)));
}

int main() {
	scanf("%d",&N);
	for(int i=1; i<=N; i++) scanf("%d%d",&A[i],&C[i]);
	for(int i=0; i<(1<<N); i++) P[i] = INF;
	for(int i=1; i<=N; i++) {
		s = i;
		go(i, (1 << (i-1)));
	}
	for(int i=1; i<(1<<N); i++) {
		D[i] = P[i];
		for(int j=(i-1)&i; j>0; j=((j-1)&i)) {
			D[i] = min(D[i], D[j] + D[i^j]);
		}
	}
	printf("%lld", D[(1<<N) - 1]);
	return 0;
}

Compilation message

telegraph.cpp: In function 'int main()':
telegraph.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
  ~~~~~^~~~~~~~~
telegraph.cpp:20:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf("%d%d",&A[i],&C[i]);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -