結果
| 問題 | No.2408 Lakes and Fish |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-05-01 11:44:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 1,414 bytes |
| 記録 | |
| コンパイル時間 | 2,225 ms |
| コンパイル使用メモリ | 199,088 KB |
| 最終ジャッジ日時 | 2025-02-21 10:01:08 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘void with_this_treasure_i_summon(std::string)’:
main.cpp:16:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:17:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define nah_id_win ios_base::sync_with_stdio(0); cin.tie(0)
#define ull unsigned long long
#define int long long
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
using namespace std;
const int MOD = 1e9 + 7;
void with_this_treasure_i_summon(string name){
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
signed main(){
nah_id_win;
int n, m; cin >> n >> m;
vector<int> l(n);
for (auto &x : l){
cin >> x;
}
vector<pair<int, pair<int, int>>> ikan(m);
for (auto &[f, bw] : ikan){
int b, w; cin >> f >> b >> w;
bw = {b, w};
}
int ans = 0; int cost = 0;
for (auto &[f, bw] : ikan){
//cout << "ikan-----------------\n";
//cout << "f " << f << "\n";
auto it1 = upper_bound(all(l), f);
int shortest = 1e18;
if (it1 != l.end()){
//cout << "kekanan " << *it1 - f << "\n";
shortest = min(shortest, *it1 - f);
}
if (it1 != l.begin()){
auto it2 = prev(it1);
//cout << "kekiri " << f - *it2 << "\n";
shortest = min(shortest, f - *it2);
}
//cout << "bedanya " << bw.se - bw.fi << "\n";
if (shortest <= (bw.se - bw.fi)){
//cout << "gelap\n";
ans += bw.se;
cost += shortest;
}
else{
//cout << "terang\n";
ans += bw.fi;
}
}
cout << ans - cost << "\n";
}
vjudge1