답안 #967364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
967364 2024-04-22T03:12:12 Z owoovo 즐거운 행로 (APIO20_fun) C++17
0 / 100
2 ms 1116 KB
#include "fun.h"
#include<bits/stdc++.h>
#define ll long long 
#define F first 
#define S second 
using namespace std;
vector<int> createFunTour(int n, int q) {
  int root=0,hf=(n+1)/2,mn=n;
  for(int i=0;i<n;i++){
    int A=attractionsBehind(0,i);
    if(A>hf&&A<mn){
      mn=A,root=i;
    }
  }
  int tr[100010],tc[3][100010];
  vector<int> ch;
  priority_queue<pair<int,int>> sub[3];
  for(int i=0;i<n;i++){
    tr[i]=hoursRequired(root,i);
    if(tr[i]==1)ch.push_back(i);
  }
  int chsz=ch.size();
  for(int j=0;j<n;j++){
    if(j==root)continue;
    int to=chsz-1;
    for(int i=0;i<chsz-1;i++){
      tc[i][j]=hoursRequired(ch[i],j);
      if(tc[i][j]<tr[j])to=i;
    }
    sub[to].push({tr[j],j});
  }
  int left=(n-1),mer=0,last=-1;
  vector<int> ans;
  while(left>0){
    pair<int,int> best={0,-1};
    for(int j=0;j<chsz;j++){
      if(j!=last&&(!sub[j].empty())&&sub[j].top().F>best.F){
        best={sub[j].top().F,j};
      }
    }
    pair<int,int> mxsz={0,0};
    for(int j=0;j<chsz;j++){
      if(sub[j].size()>mxsz.F){
        mxsz={sub[j].size(),j};
      }
    }
    if(mer==0&&mxsz.F*2>left){
      mer=1;
      if(last==mxsz.S)last=(last+1)%3;
      int lf=3-last-mxsz.S;
      if(((!sub[lf].empty())&&(!sub[last].empty()))&&sub[lf].top().F>sub[last].top().F){
        left--;
        last=lf;
        auto [x,y]=sub[last].top();
        sub[last].pop();
        ans.push_back(y);
      }
      if(last==mxsz.S)last=(last+1)%3;
      lf=3-last-mxsz.S;
      while(!sub[lf].empty()){
        sub[last].push(sub[lf].top());
        sub[lf].pop();
      }
      best.S=mxsz.S;
    }
    if(best.S==-1){
      for(int j=0;j<chsz;j++){
        if(!sub[j].empty())best.S=j;
      }
    }
    assert(!sub[best.S].empty());
    auto [x,y]=sub[best.S].top();
    sub[best.S].pop();
    last=best.S;
    ans.push_back(y);
    left--;
  }
  ans.push_back(root);
  return ans;
}

Compilation message

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:43:23: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |       if(sub[j].size()>mxsz.F){
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Runtime error 2 ms 1112 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Runtime error 2 ms 1112 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Runtime error 2 ms 1112 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Runtime error 1 ms 1116 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Runtime error 2 ms 1112 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -