개발자 톡

연습문제 톡 [한양대 HCPC 2023] Phi Squared

[한양대 HCPC 2023] Phi Squared / C++ 풀이 뭐가 틀린건지....

등록일
2024-06-19 21:49:49
조회수
338
작성자
phw0503

TC 1, 5, 12, 14 번을 제외하고 다 틀립니다.

뭐가 틀린거지 알려주시면 감사하겠습니다.


#include <iostream>

#include <deque>


using namespace std;


int main(int argc, char** argv)

{

  deque<pair<int,int>> behindq;

  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {

    int tmp;

    cin >> tmp;

    behindq.push_back(make_pair(tmp, i + 1));

  }


  while (1 < behindq.size()) {

    deque<pair<int,int>> frontq;

    while(!behindq.empty()) {

      pair<int,int> now = behindq.front();

      behindq.pop_front();

      if (!frontq.empty() && frontq.back().first <= now.first && !behindq.empty() && behindq.front().first <= now.first) {

        now.first += frontq.back().first + behindq.front().first;

        frontq.pop_back();

        behindq.pop_front();

      }

      else if (!frontq.empty() && frontq.back().first <= now.first) {

        now.first += frontq.back().first;

        frontq.pop_back();

      }

      else if (!behindq.empty() && behindq.front().first <= now.first) {

        now.first += behindq.front().first;

        behindq.pop_front();

      }

      frontq.push_back(now);

    }

    behindq = frontq;

  }

  cout << behindq.front().first << endl;

  cout << behindq.front().second << endl;

  return 0;

}

#[한양대_HCPC_2023]_Phi_Squared

이 카테고리의 톡 더보기