답안 #136962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136962 2019-07-26T16:44:55 Z DanerZein Shortcut (IOI16_shortcut) C++14
0 / 100
598 ms 768 KB
#include "shortcut.h"
#include <bits/stdc++.h>
#define MAX 51000000001
using namespace std;
typedef pair<int,int> ii;
typedef vector<ii> vi;
vector<vi>G;
int ml;
vector<long long> dist(20);
void bfs(int u){
  
  dist[u]=0;
  vector<int>vis(ml,0);
  queue<int>q;
  q.push(u);
  vis[u]=1;
  while(!q.empty()){
   int v=q.front();
   q.pop();
   vis[v]=0;
   for(int i=0;i<G[v].size();i++){
    long long x=G[v][i].first;
    long long w=G[v][i].second;
    if(dist[v]+w<=dist[x]){
      dist[x]=dist[v]+w;
    if(vis[x]==0){
     q.push(x);
     vis[x]=1;
    }
   }
  }
 }
}
long long find_shortcut(int  n, std::vector<int> l, std::vector<int> d, int c){ 
   ml=2*n;
   G.resize(2*n);
   for(long long i=0;i<l.size();i++){
    G[i+1].push_back(ii(i,l[i]));
    G[i].push_back(ii(i+1,l[i]));
   }
   for(long long i=0;i<d.size();i++){
    if(d[i]!=0){
      G[i+n].push_back(ii(i,d[i]));
      G[i].push_back(ii(i+n,d[i]));
    }
   }
   long long mi=MAX;
   for(long long i=0;i<n;i++){
    for(long long j=i+1;j<n;j++){
    G[i].push_back(ii(j,c));
    G[j].push_back(ii(i,c));
    long long ma=-1;
    /*  fill(dist.begin(),dist.end(),MAX);
    long long no;
    bfs(0);
    for(int k=0;k<2*n;k++){
      if(!G[k].empty()){
	cout<<dist[k]<<" ";
	if(ma<dist[k]){
	ma=max(ma,dist[k]);
	no=k;
	}
      }
    }
    cout<<endl;
    //cout<<ma<<endl;
    fill(dist.begin(),dist.end(),MAX);
    bfs(no);
    for(int k=0;k<2*n;k++){
      if(!G[k].empty()){
	if(ma<=dist[k]){
	ma=max(ma,dist[k]);
	no=k;
      
      }
		cout<<dist[k]<<" ";
      }
    }
    cout<<endl;
    //cout<<ma<<endl;
    fill(dist.begin(),dist.end(),MAX);
    bfs(no);
    for(int k=0;k<2*n;k++){
      if(!G[k].empty()){
	if(ma<=dist[k]){
	ma=max(ma,dist[k]);
	no=k;
	}
		cout<<dist[k]<<" ";
      }
    }
    cout<<endl<<endl;*/
    for(int l=0;l<G.size();l++){
      if(G[l].empty()){
	continue;
      }
      fill(dist.begin(),dist.end(),MAX);
      bfs(l);
      for(int k=0;k<G.size();k++){
	if(!G[k].empty()){
	  if(dist[k]==12 and i==0 and j==4){
	    //  cout<<l<<" "<<k<<endl;
	  }
	  ma=max(ma,dist[k]);
	}
      }
    }
    // cout<<ma<<endl<<endl;
    G[i].pop_back();
    G[j].pop_back();
     mi=min(mi,ma);
   }
  }
  return mi;         
}

Compilation message

shortcut.cpp: In function 'void bfs(int)':
shortcut.cpp:21:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<G[v].size();i++){
                ~^~~~~~~~~~~~
shortcut.cpp: In function 'long long int find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:37:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(long long i=0;i<l.size();i++){
                      ~^~~~~~~~~
shortcut.cpp:41:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(long long i=0;i<d.size();i++){
                      ~^~~~~~~~~
shortcut.cpp:93:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int l=0;l<G.size();l++){
                 ~^~~~~~~~~
shortcut.cpp:99:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int k=0;k<G.size();k++){
                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 2 ms 376 KB n = 4, 21 is a correct answer
4 Correct 2 ms 376 KB n = 3, 4 is a correct answer
5 Correct 2 ms 376 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 396 KB n = 3, 29 is a correct answer
8 Correct 2 ms 376 KB n = 2, 3 is a correct answer
9 Correct 2 ms 376 KB n = 2, 3 is a correct answer
10 Correct 2 ms 256 KB n = 2, 2000000001 is a correct answer
11 Correct 2 ms 376 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
13 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
14 Correct 2 ms 376 KB n = 4, 3000000001 is a correct answer
15 Correct 2 ms 256 KB n = 4, 4000000000 is a correct answer
16 Correct 2 ms 376 KB n = 5, 4000000000 is a correct answer
17 Correct 3 ms 376 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 376 KB n = 10, 3189 is a correct answer
19 Correct 2 ms 256 KB n = 10, 7000000000 is a correct answer
20 Correct 2 ms 256 KB n = 5, 12 is a correct answer
21 Correct 2 ms 256 KB n = 5, 25 is a correct answer
22 Correct 2 ms 256 KB n = 2, 122 is a correct answer
23 Correct 3 ms 256 KB n = 10, 117 is a correct answer
24 Correct 3 ms 376 KB n = 10, 336 is a correct answer
25 Correct 3 ms 256 KB n = 10, 438 is a correct answer
26 Correct 3 ms 376 KB n = 10, 206 is a correct answer
27 Correct 2 ms 256 KB n = 10, 636 is a correct answer
28 Correct 2 ms 376 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 380 KB n = 10, 10992 is a correct answer
30 Correct 2 ms 356 KB n = 10, 3112 is a correct answer
31 Runtime error 598 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 2 ms 376 KB n = 4, 21 is a correct answer
4 Correct 2 ms 376 KB n = 3, 4 is a correct answer
5 Correct 2 ms 376 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 396 KB n = 3, 29 is a correct answer
8 Correct 2 ms 376 KB n = 2, 3 is a correct answer
9 Correct 2 ms 376 KB n = 2, 3 is a correct answer
10 Correct 2 ms 256 KB n = 2, 2000000001 is a correct answer
11 Correct 2 ms 376 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
13 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
14 Correct 2 ms 376 KB n = 4, 3000000001 is a correct answer
15 Correct 2 ms 256 KB n = 4, 4000000000 is a correct answer
16 Correct 2 ms 376 KB n = 5, 4000000000 is a correct answer
17 Correct 3 ms 376 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 376 KB n = 10, 3189 is a correct answer
19 Correct 2 ms 256 KB n = 10, 7000000000 is a correct answer
20 Correct 2 ms 256 KB n = 5, 12 is a correct answer
21 Correct 2 ms 256 KB n = 5, 25 is a correct answer
22 Correct 2 ms 256 KB n = 2, 122 is a correct answer
23 Correct 3 ms 256 KB n = 10, 117 is a correct answer
24 Correct 3 ms 376 KB n = 10, 336 is a correct answer
25 Correct 3 ms 256 KB n = 10, 438 is a correct answer
26 Correct 3 ms 376 KB n = 10, 206 is a correct answer
27 Correct 2 ms 256 KB n = 10, 636 is a correct answer
28 Correct 2 ms 376 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 380 KB n = 10, 10992 is a correct answer
30 Correct 2 ms 356 KB n = 10, 3112 is a correct answer
31 Runtime error 598 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 2 ms 376 KB n = 4, 21 is a correct answer
4 Correct 2 ms 376 KB n = 3, 4 is a correct answer
5 Correct 2 ms 376 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 396 KB n = 3, 29 is a correct answer
8 Correct 2 ms 376 KB n = 2, 3 is a correct answer
9 Correct 2 ms 376 KB n = 2, 3 is a correct answer
10 Correct 2 ms 256 KB n = 2, 2000000001 is a correct answer
11 Correct 2 ms 376 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
13 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
14 Correct 2 ms 376 KB n = 4, 3000000001 is a correct answer
15 Correct 2 ms 256 KB n = 4, 4000000000 is a correct answer
16 Correct 2 ms 376 KB n = 5, 4000000000 is a correct answer
17 Correct 3 ms 376 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 376 KB n = 10, 3189 is a correct answer
19 Correct 2 ms 256 KB n = 10, 7000000000 is a correct answer
20 Correct 2 ms 256 KB n = 5, 12 is a correct answer
21 Correct 2 ms 256 KB n = 5, 25 is a correct answer
22 Correct 2 ms 256 KB n = 2, 122 is a correct answer
23 Correct 3 ms 256 KB n = 10, 117 is a correct answer
24 Correct 3 ms 376 KB n = 10, 336 is a correct answer
25 Correct 3 ms 256 KB n = 10, 438 is a correct answer
26 Correct 3 ms 376 KB n = 10, 206 is a correct answer
27 Correct 2 ms 256 KB n = 10, 636 is a correct answer
28 Correct 2 ms 376 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 380 KB n = 10, 10992 is a correct answer
30 Correct 2 ms 356 KB n = 10, 3112 is a correct answer
31 Runtime error 598 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 2 ms 376 KB n = 4, 21 is a correct answer
4 Correct 2 ms 376 KB n = 3, 4 is a correct answer
5 Correct 2 ms 376 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 396 KB n = 3, 29 is a correct answer
8 Correct 2 ms 376 KB n = 2, 3 is a correct answer
9 Correct 2 ms 376 KB n = 2, 3 is a correct answer
10 Correct 2 ms 256 KB n = 2, 2000000001 is a correct answer
11 Correct 2 ms 376 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
13 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
14 Correct 2 ms 376 KB n = 4, 3000000001 is a correct answer
15 Correct 2 ms 256 KB n = 4, 4000000000 is a correct answer
16 Correct 2 ms 376 KB n = 5, 4000000000 is a correct answer
17 Correct 3 ms 376 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 376 KB n = 10, 3189 is a correct answer
19 Correct 2 ms 256 KB n = 10, 7000000000 is a correct answer
20 Correct 2 ms 256 KB n = 5, 12 is a correct answer
21 Correct 2 ms 256 KB n = 5, 25 is a correct answer
22 Correct 2 ms 256 KB n = 2, 122 is a correct answer
23 Correct 3 ms 256 KB n = 10, 117 is a correct answer
24 Correct 3 ms 376 KB n = 10, 336 is a correct answer
25 Correct 3 ms 256 KB n = 10, 438 is a correct answer
26 Correct 3 ms 376 KB n = 10, 206 is a correct answer
27 Correct 2 ms 256 KB n = 10, 636 is a correct answer
28 Correct 2 ms 376 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 380 KB n = 10, 10992 is a correct answer
30 Correct 2 ms 356 KB n = 10, 3112 is a correct answer
31 Runtime error 598 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 2 ms 376 KB n = 4, 21 is a correct answer
4 Correct 2 ms 376 KB n = 3, 4 is a correct answer
5 Correct 2 ms 376 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 396 KB n = 3, 29 is a correct answer
8 Correct 2 ms 376 KB n = 2, 3 is a correct answer
9 Correct 2 ms 376 KB n = 2, 3 is a correct answer
10 Correct 2 ms 256 KB n = 2, 2000000001 is a correct answer
11 Correct 2 ms 376 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
13 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
14 Correct 2 ms 376 KB n = 4, 3000000001 is a correct answer
15 Correct 2 ms 256 KB n = 4, 4000000000 is a correct answer
16 Correct 2 ms 376 KB n = 5, 4000000000 is a correct answer
17 Correct 3 ms 376 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 376 KB n = 10, 3189 is a correct answer
19 Correct 2 ms 256 KB n = 10, 7000000000 is a correct answer
20 Correct 2 ms 256 KB n = 5, 12 is a correct answer
21 Correct 2 ms 256 KB n = 5, 25 is a correct answer
22 Correct 2 ms 256 KB n = 2, 122 is a correct answer
23 Correct 3 ms 256 KB n = 10, 117 is a correct answer
24 Correct 3 ms 376 KB n = 10, 336 is a correct answer
25 Correct 3 ms 256 KB n = 10, 438 is a correct answer
26 Correct 3 ms 376 KB n = 10, 206 is a correct answer
27 Correct 2 ms 256 KB n = 10, 636 is a correct answer
28 Correct 2 ms 376 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 380 KB n = 10, 10992 is a correct answer
30 Correct 2 ms 356 KB n = 10, 3112 is a correct answer
31 Runtime error 598 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 2 ms 376 KB n = 4, 21 is a correct answer
4 Correct 2 ms 376 KB n = 3, 4 is a correct answer
5 Correct 2 ms 376 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 396 KB n = 3, 29 is a correct answer
8 Correct 2 ms 376 KB n = 2, 3 is a correct answer
9 Correct 2 ms 376 KB n = 2, 3 is a correct answer
10 Correct 2 ms 256 KB n = 2, 2000000001 is a correct answer
11 Correct 2 ms 376 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
13 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
14 Correct 2 ms 376 KB n = 4, 3000000001 is a correct answer
15 Correct 2 ms 256 KB n = 4, 4000000000 is a correct answer
16 Correct 2 ms 376 KB n = 5, 4000000000 is a correct answer
17 Correct 3 ms 376 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 376 KB n = 10, 3189 is a correct answer
19 Correct 2 ms 256 KB n = 10, 7000000000 is a correct answer
20 Correct 2 ms 256 KB n = 5, 12 is a correct answer
21 Correct 2 ms 256 KB n = 5, 25 is a correct answer
22 Correct 2 ms 256 KB n = 2, 122 is a correct answer
23 Correct 3 ms 256 KB n = 10, 117 is a correct answer
24 Correct 3 ms 376 KB n = 10, 336 is a correct answer
25 Correct 3 ms 256 KB n = 10, 438 is a correct answer
26 Correct 3 ms 376 KB n = 10, 206 is a correct answer
27 Correct 2 ms 256 KB n = 10, 636 is a correct answer
28 Correct 2 ms 376 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 380 KB n = 10, 10992 is a correct answer
30 Correct 2 ms 356 KB n = 10, 3112 is a correct answer
31 Runtime error 598 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 2 ms 376 KB n = 4, 21 is a correct answer
4 Correct 2 ms 376 KB n = 3, 4 is a correct answer
5 Correct 2 ms 376 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 396 KB n = 3, 29 is a correct answer
8 Correct 2 ms 376 KB n = 2, 3 is a correct answer
9 Correct 2 ms 376 KB n = 2, 3 is a correct answer
10 Correct 2 ms 256 KB n = 2, 2000000001 is a correct answer
11 Correct 2 ms 376 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
13 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
14 Correct 2 ms 376 KB n = 4, 3000000001 is a correct answer
15 Correct 2 ms 256 KB n = 4, 4000000000 is a correct answer
16 Correct 2 ms 376 KB n = 5, 4000000000 is a correct answer
17 Correct 3 ms 376 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 376 KB n = 10, 3189 is a correct answer
19 Correct 2 ms 256 KB n = 10, 7000000000 is a correct answer
20 Correct 2 ms 256 KB n = 5, 12 is a correct answer
21 Correct 2 ms 256 KB n = 5, 25 is a correct answer
22 Correct 2 ms 256 KB n = 2, 122 is a correct answer
23 Correct 3 ms 256 KB n = 10, 117 is a correct answer
24 Correct 3 ms 376 KB n = 10, 336 is a correct answer
25 Correct 3 ms 256 KB n = 10, 438 is a correct answer
26 Correct 3 ms 376 KB n = 10, 206 is a correct answer
27 Correct 2 ms 256 KB n = 10, 636 is a correct answer
28 Correct 2 ms 376 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 380 KB n = 10, 10992 is a correct answer
30 Correct 2 ms 356 KB n = 10, 3112 is a correct answer
31 Runtime error 598 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n = 4, 80 is a correct answer
2 Correct 3 ms 376 KB n = 9, 110 is a correct answer
3 Correct 2 ms 376 KB n = 4, 21 is a correct answer
4 Correct 2 ms 376 KB n = 3, 4 is a correct answer
5 Correct 2 ms 376 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 396 KB n = 3, 29 is a correct answer
8 Correct 2 ms 376 KB n = 2, 3 is a correct answer
9 Correct 2 ms 376 KB n = 2, 3 is a correct answer
10 Correct 2 ms 256 KB n = 2, 2000000001 is a correct answer
11 Correct 2 ms 376 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
13 Correct 2 ms 376 KB n = 3, 3000000000 is a correct answer
14 Correct 2 ms 376 KB n = 4, 3000000001 is a correct answer
15 Correct 2 ms 256 KB n = 4, 4000000000 is a correct answer
16 Correct 2 ms 376 KB n = 5, 4000000000 is a correct answer
17 Correct 3 ms 376 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 376 KB n = 10, 3189 is a correct answer
19 Correct 2 ms 256 KB n = 10, 7000000000 is a correct answer
20 Correct 2 ms 256 KB n = 5, 12 is a correct answer
21 Correct 2 ms 256 KB n = 5, 25 is a correct answer
22 Correct 2 ms 256 KB n = 2, 122 is a correct answer
23 Correct 3 ms 256 KB n = 10, 117 is a correct answer
24 Correct 3 ms 376 KB n = 10, 336 is a correct answer
25 Correct 3 ms 256 KB n = 10, 438 is a correct answer
26 Correct 3 ms 376 KB n = 10, 206 is a correct answer
27 Correct 2 ms 256 KB n = 10, 636 is a correct answer
28 Correct 2 ms 376 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 380 KB n = 10, 10992 is a correct answer
30 Correct 2 ms 356 KB n = 10, 3112 is a correct answer
31 Runtime error 598 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Halted 0 ms 0 KB -