답안 #288507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
288507 2020-09-01T14:37:12 Z davi_bart Simurgh (IOI17_simurgh) C++14
51 / 100
1184 ms 11244 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ld long double

int count_common_roads(const vector<int>& r);
int ask(set<int> o){
  vector<int> x;
  for(int y:o)x.push_back(y);
  return count_common_roads(x);
}
vector<pair<int,int> >kkk;
int N;
set<int> ans;
set<pair<int,int> > p[600];
vector<int> grafo(int pos){
  vector<int> group(N+2,-1);
  set<int> v;
  vector<bool> vis(N+2,0);

  queue<pair<int,int> >q;

  for(int i=0;i<N;i++){
    if(vis[i] || i==pos)continue;
    q.push({i,-1});
    while(!q.empty()){
      auto &[pp,idx]=q.front();
      q.pop();
      if(vis[pp])continue;
      vis[pp]=1;
      group[pp]=i;
      if(idx!=-1)v.insert(idx);
      for(auto x:p[pp]){
        if(x.first!=pos)q.push({x.first,x.second});
      }
    }
  }

  vector<int> arc[N+2];
  for(auto &[a,b]:p[pos]){
    arc[group[a]].push_back(b);
  }

  vector<int> prendere;
  vector<bool> sist(N+10,0);
  for(int i=0;i<N;i++){
    if(arc[i].size()==0)continue;
    v.insert(arc[i][0]);
    for(int j=0;j<arc[i].size();j++){
      if(ans.find(arc[i][j])!=ans.end()){
        v.erase(arc[i][0]);
        v.insert(arc[i][j]);
        swap(arc[i][0],arc[i][j]);
        sist[i]=1;
        break;
      }
    }
  }

  for(int i=0;i<N;i++){
    if(arc[i].size()==0)continue;
    if(arc[i].size()==1){
      prendere.push_back(arc[i][0]);
      continue;
    }
    int ma=ask(v);
    vector<int> qq={ma};
    int prec=arc[i][0];
    for(int j=1;j<arc[i].size();j++){
      if(kkk[arc[i][j]].first<pos){
          qq.push_back(-1);
          continue;
      }
      v.erase(prec);
      v.insert(arc[i][j]);
      prec=arc[i][j];
      qq.push_back(ask(v));
      ma=max(ma,qq.back());
    }
    for(int j=0;j<arc[i].size();j++){
      if(qq[j]==ma){
        prendere.push_back(arc[i][j]);
      }
    }
  }
  return prendere;
}

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v){
  N=n;
  for(int i=0;i<u.size();i++){
    p[u[i]].insert({v[i],i});
    p[v[i]].insert({u[i],i});
    kkk.push_back({min(u[i],v[i]),max(u[i],v[i])});
  }
	for(int i=0;i<N;i++){
    auto x=grafo(i);
    for(int j:x)ans.insert(j);
    if(ans.size()==N-1)break;
	}
	vector<int> sol;
	for(int x:ans)sol.push_back(x);
	return sol;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> grafo(int)':
simurgh.cpp:30:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |       auto &[pp,idx]=q.front();
      |             ^
simurgh.cpp:43:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |   for(auto &[a,b]:p[pos]){
      |             ^
simurgh.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int j=0;j<arc[i].size();j++){
      |                 ~^~~~~~~~~~~~~~
simurgh.cpp:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int j=1;j<arc[i].size();j++){
      |                 ~^~~~~~~~~~~~~~
simurgh.cpp:83:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int j=0;j<arc[i].size();j++){
      |                 ~^~~~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:94:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   for(int i=0;i<u.size();i++){
      |               ~^~~~~~~~~
simurgh.cpp:102:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  102 |     if(ans.size()==N-1)break;
      |        ~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 404 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 404 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 9 ms 512 KB correct
15 Correct 3 ms 512 KB correct
16 Correct 9 ms 512 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 4 ms 384 KB correct
19 Correct 11 ms 544 KB correct
20 Correct 5 ms 512 KB correct
21 Correct 7 ms 512 KB correct
22 Correct 6 ms 404 KB correct
23 Correct 6 ms 384 KB correct
24 Correct 6 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 5 ms 384 KB correct
27 Correct 5 ms 384 KB correct
28 Correct 3 ms 384 KB correct
29 Correct 2 ms 384 KB correct
30 Correct 5 ms 384 KB correct
31 Correct 5 ms 384 KB correct
32 Correct 5 ms 384 KB correct
33 Correct 5 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 404 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 9 ms 512 KB correct
15 Correct 3 ms 512 KB correct
16 Correct 9 ms 512 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 4 ms 384 KB correct
19 Correct 11 ms 544 KB correct
20 Correct 5 ms 512 KB correct
21 Correct 7 ms 512 KB correct
22 Correct 6 ms 404 KB correct
23 Correct 6 ms 384 KB correct
24 Correct 6 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 5 ms 384 KB correct
27 Correct 5 ms 384 KB correct
28 Correct 3 ms 384 KB correct
29 Correct 2 ms 384 KB correct
30 Correct 5 ms 384 KB correct
31 Correct 5 ms 384 KB correct
32 Correct 5 ms 384 KB correct
33 Correct 5 ms 384 KB correct
34 Correct 1184 ms 4468 KB correct
35 Correct 1126 ms 4596 KB correct
36 Correct 719 ms 3188 KB correct
37 Correct 50 ms 640 KB correct
38 Correct 1179 ms 4572 KB correct
39 Correct 827 ms 4084 KB correct
40 Correct 683 ms 3188 KB correct
41 Correct 1132 ms 4860 KB correct
42 Correct 1160 ms 4808 KB correct
43 Correct 567 ms 2432 KB correct
44 Correct 433 ms 2180 KB correct
45 Correct 533 ms 2304 KB correct
46 Correct 371 ms 1852 KB correct
47 Correct 163 ms 1024 KB correct
48 Correct 27 ms 384 KB correct
49 Correct 55 ms 512 KB correct
50 Correct 169 ms 1144 KB correct
51 Correct 494 ms 2424 KB correct
52 Correct 441 ms 2072 KB correct
53 Correct 375 ms 2040 KB correct
54 Correct 560 ms 2552 KB correct
55 Correct 515 ms 2436 KB correct
56 Correct 507 ms 2308 KB correct
57 Correct 569 ms 2552 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Incorrect 1044 ms 11244 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 404 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 1 ms 384 KB correct
6 Correct 1 ms 384 KB correct
7 Correct 0 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 9 ms 512 KB correct
15 Correct 3 ms 512 KB correct
16 Correct 9 ms 512 KB correct
17 Correct 7 ms 512 KB correct
18 Correct 4 ms 384 KB correct
19 Correct 11 ms 544 KB correct
20 Correct 5 ms 512 KB correct
21 Correct 7 ms 512 KB correct
22 Correct 6 ms 404 KB correct
23 Correct 6 ms 384 KB correct
24 Correct 6 ms 384 KB correct
25 Correct 1 ms 384 KB correct
26 Correct 5 ms 384 KB correct
27 Correct 5 ms 384 KB correct
28 Correct 3 ms 384 KB correct
29 Correct 2 ms 384 KB correct
30 Correct 5 ms 384 KB correct
31 Correct 5 ms 384 KB correct
32 Correct 5 ms 384 KB correct
33 Correct 5 ms 384 KB correct
34 Correct 1184 ms 4468 KB correct
35 Correct 1126 ms 4596 KB correct
36 Correct 719 ms 3188 KB correct
37 Correct 50 ms 640 KB correct
38 Correct 1179 ms 4572 KB correct
39 Correct 827 ms 4084 KB correct
40 Correct 683 ms 3188 KB correct
41 Correct 1132 ms 4860 KB correct
42 Correct 1160 ms 4808 KB correct
43 Correct 567 ms 2432 KB correct
44 Correct 433 ms 2180 KB correct
45 Correct 533 ms 2304 KB correct
46 Correct 371 ms 1852 KB correct
47 Correct 163 ms 1024 KB correct
48 Correct 27 ms 384 KB correct
49 Correct 55 ms 512 KB correct
50 Correct 169 ms 1144 KB correct
51 Correct 494 ms 2424 KB correct
52 Correct 441 ms 2072 KB correct
53 Correct 375 ms 2040 KB correct
54 Correct 560 ms 2552 KB correct
55 Correct 515 ms 2436 KB correct
56 Correct 507 ms 2308 KB correct
57 Correct 569 ms 2552 KB correct
58 Correct 1 ms 384 KB correct
59 Correct 1 ms 384 KB correct
60 Incorrect 1044 ms 11244 KB WA in grader: NO
61 Halted 0 ms 0 KB -