結果
問題 | No.2408 Lakes and Fish |
ユーザー | vjudge1 |
提出日時 | 2024-05-02 00:56:13 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,616 bytes |
コンパイル時間 | 5,903 ms |
コンパイル使用メモリ | 288,132 KB |
実行使用メモリ | 9,824 KB |
最終ジャッジ日時 | 2024-05-02 00:56:23 |
合計ジャッジ時間 | 8,530 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,812 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:63:19: warning: 'c' may be used uninitialized [-Wmaybe-uninitialized] 63 | c += abs(tree[closest]-b); | ~~^~~~~~~~~~~~~~~~~~~~~~~ main.cpp:41:30: note: 'c' was declared here 41 | int closest, move, diff, c, ans; | ^
ソースコード
#include<bits/stdc++.h> using namespace std; vector<int> tree; bool binser(int l, int r, int x){ if(l>r) return false; int mid = l+(r-l)/2; if(tree[mid] == x) return true; else if(tree[mid] < x) return binser(mid+1, r, x); else return binser(l, mid-1, x); } int dark(int l, int r, int x, int diff){ if(l>r) return -1; int mid = l+(r-l)/2; int temp; if(abs(tree[mid]-x) < diff){ temp = abs(tree[mid]-x); int end = dark(l, r, x, temp); if(end == -1){ return mid; } else return end; } else { if(tree[mid] < x) return dark(mid+1, r, x, diff); else return dark(l, mid-1, x, diff); } } int main(){ int n, m, a, b; cin >> n >> m; for(int i = 0; i < n; i++){ cin >> a; tree.push_back(a); } vector<vector<int>> fish; int pow = 0; int closest, move, diff, c, ans; int p, q, s, temp; for(int i = 0; i < m; i++){ cin >> p >> q >> s; diff = s - q; vector<int> temp = {diff, p, q, s}; fish.push_back(temp); } sort(fish.begin(), fish.end()); reverse(fish.begin(), fish.end()); for(int i = 0; i < m; i++){ b = fish[i][1]; if(binser(0, n, b)){ pow += fish[i][3]; } else { pow += fish[i][2]; diff = fish[i][3] - fish[i][2]; closest = dark(0, n, b, diff); if(closest != -1){ pow += diff; c += abs(tree[closest]-b); } } } ans = pow - c; cout << ans << endl; return 0; }