답안 #137312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137312 2019-07-27T12:45:27 Z cfalas Shortcut (IOI16_shortcut) C++14
0 / 100
2 ms 376 KB
#include "shortcut.h"
#include<bits/stdc++.h>
#define INF 1000000
#define F first
#define S second

using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
vector<vector<ii> > adj;
int ext[1000], len[1000];
vector<bool> vis;
int furth;
int dist;
int diamet;
long long distdfs(int s, int t){
	vis[s] = true;
	if(s==t) return dist;
	for(int i=0;i<adj[s].size();i++){
		if(!vis[adj[s][i].F]){
			dist+=adj[s][i].S;
			if(distdfs(adj[s][i].F, t)) return dist;
			dist-=adj[s][i].S;
		}
	}
	return 0;
}

int m;
long long find_diameter(){
	int maxdiam = 0;
	int prsum[m];
	prsum[0] = len[0];
	for(int i=1;i<m;i++) prsum[i] = prsum[i-1] + len[i];
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			maxdiam = max(maxdiam, ext[i] + prsum[j] - prsum[i-1] + ext[j]);
		}
	}
	return maxdiam;
}

long long find_shortcut(int n, vector<int> l, vector<int> d, int c){
	m = n;
	for(int i=0;i<n;i++) ext[i] = d[i], len[i]=l[i];
	adj.assign(n, vii());
	for(int i=0;i<n-1;i++){
		adj[i].push_back(ii(i+1, l[i]));
		adj[i+1].push_back(ii(i, l[i]));
	}
	long long diameter = find_diameter();
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			//cout<<i<<" "<<j<<endl;
			dist = 0;
			vis.assign(n, false);
			distdfs(i, j);
			dist+=ext[i] + ext[j];
			long long cc = c + ext[i] + ext[j];
			//cout<<dist<<" "<<cc<<endl;
			if(dist==diameter){
				//cout<<"try\n";
				//diameter = min(diameter, diameterleft(i) + c + diameterright(j));
				diameter = cc;
				return diameter;

			}
		}
	}
	return diameter;
}

Compilation message

shortcut.cpp: In function 'long long int distdfs(int, int)':
shortcut.cpp:19:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<adj[s].size();i++){
              ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Incorrect 2 ms 376 KB n = 9, incorrect answer: jury 110 vs contestant 140
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Incorrect 2 ms 376 KB n = 9, incorrect answer: jury 110 vs contestant 140
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Incorrect 2 ms 376 KB n = 9, incorrect answer: jury 110 vs contestant 140
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Incorrect 2 ms 376 KB n = 9, incorrect answer: jury 110 vs contestant 140
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Incorrect 2 ms 376 KB n = 9, incorrect answer: jury 110 vs contestant 140
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Incorrect 2 ms 376 KB n = 9, incorrect answer: jury 110 vs contestant 140
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Incorrect 2 ms 376 KB n = 9, incorrect answer: jury 110 vs contestant 140
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB n = 4, 80 is a correct answer
2 Incorrect 2 ms 376 KB n = 9, incorrect answer: jury 110 vs contestant 140
3 Halted 0 ms 0 KB -