結果

問題 No.324 落ちてた閉路グラフ
ユーザー simansiman
提出日時 2016-04-03 01:57:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,977 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 88,500 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 10:42:23
合計ジャッジ時間 6,761 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 372 ms
6,940 KB
testcase_05 AC 16 ms
6,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 411 ms
6,944 KB
testcase_09 AC 540 ms
6,944 KB
testcase_10 AC 447 ms
6,940 KB
testcase_11 AC 596 ms
6,944 KB
testcase_12 AC 608 ms
6,940 KB
testcase_13 AC 214 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 WA -
testcase_26 AC 2 ms
6,940 KB
testcase_27 WA -
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>
#include <time.h>
#include <string>
#include <string.h>
#include <sstream>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

struct Edge {
  int from;
  int to;
  int value;
  bool valid;

  Edge(int from = -1, int to = -1, int value = -1){
    this->from = from;
    this->to = to;
    this->value = value;
    this->valid = true;
  }
};

struct Node {
  int id;
  int value;

  Node(int id = -1, int value = -1){ 
    this->id = id;
    this->value = value;
  }

  bool operator >(const Node &e) const{
    return value > e.value;
  }    
};

vector<Edge> edgeList;
vector<Node> nodeList;
map<int, bool> pickList;
int n, m;
priority_queue<Node, vector<Node>, greater<Node> > pque;

void updateNodeValue(){
  pque = priority_queue<Node, vector<Node>, greater<Node> >();

  for(int i = 0; i < n; i++){
    Edge le = edgeList[(i+n-1)%n];
    Edge re = edgeList[(i+n)%n];
    int value = 0;

    if(le.valid){
      value += le.value;
    }
    if(re.valid){
      value += re.value;
    }

    if(!pickList[i]){
      pque.push(Node(i, value));
    }
  }
}

int main(){
  cin >> n >> m;

  int w;
  for(int i = 0; i < n; i++){
    cin >> w;
    Edge edge(i, (i+1)%n, w);
    edgeList.push_back(edge);

    Node node;
    nodeList.push_back(node);
  }

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

    Node node = pque.top(); pque.pop();
    edgeList[(node.id+n-1)%n].valid = false;
    edgeList[(node.id+n)%n].valid = false;
    pickList[node.id] = true;
  }

  int answer = 0;

  while(!pque.empty()){
    Node node = pque.top(); pque.pop();

    //fprintf(stderr,"node %d: value %d\n", node.id, node.value);
  }

  for(int i = 0; i < n; i++){
    Edge edge = edgeList[i];

    if(edge.valid){
      answer += edge.value;
    }
  }

  cout << answer << endl;

  return 0;
}
0