結果
問題 |
No.324 落ちてた閉路グラフ
|
ユーザー |
![]() |
提出日時 | 2016-04-03 01:57:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,977 bytes |
コンパイル時間 | 877 ms |
コンパイル使用メモリ | 88,548 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-02 12:33:03 |
合計ジャッジ時間 | 6,731 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 WA * 11 |
ソースコード
#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; }