結果

問題 No.2408 Lakes and Fish
ユーザー vjudge1vjudge1
提出日時 2024-05-01 22:18:07
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,615 bytes
コンパイル時間 2,728 ms
コンパイル使用メモリ 247,948 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 22:18:12
合計ジャッジ時間 4,633 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 43 ms
6,944 KB
testcase_05 AC 41 ms
6,940 KB
testcase_06 AC 44 ms
6,940 KB
testcase_07 AC 53 ms
6,944 KB
testcase_08 AC 52 ms
6,940 KB
testcase_09 AC 58 ms
6,940 KB
testcase_10 AC 58 ms
6,944 KB
testcase_11 AC 29 ms
6,940 KB
testcase_12 AC 39 ms
6,940 KB
testcase_13 AC 11 ms
6,944 KB
testcase_14 AC 23 ms
6,940 KB
testcase_15 AC 43 ms
6,944 KB
testcase_16 AC 16 ms
6,944 KB
testcase_17 AC 13 ms
6,944 KB
testcase_18 AC 25 ms
6,940 KB
testcase_19 AC 41 ms
6,940 KB
testcase_20 AC 38 ms
6,940 KB
testcase_21 AC 41 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:52:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'total' may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:18:8: note: 'total' was declared here
   18 |     ll total;
      |        ^~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

int main() {
    cin.tie(NULL); cout.tie(NULL); ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    ll tree[n], light[m], dark[m], fish[m];
    for (int i = 0; i<n; i++) {
        cin >> tree[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> fish[i] >> light[i] >> dark[i];
    }
    sort(tree, tree+n);
    ll total;
    for (int i = 0; i < m; i++) {
        ll closest = 0;
        if (fish[i] < tree[0]) closest = abs(tree[0] - fish[i]);
        else if (fish[i] > tree[n-1]) closest = abs(tree[n-1] - fish[i]);
        else {
            ll mid, left = 0, right = n-1;
            while (left <= right) {
                mid = (left + right) / 2;
                if (tree[mid] == fish[i]) {
                    closest = 0;
                    break;
                }

                else if (fish[i] < tree[mid]) {
                    if (fish[i] > tree[mid-1]) {
                        closest = min(abs(fish[i] - tree[mid-1]), abs(fish[i] - tree[mid]));
                        break;
                    }
                    right = mid - 1; 
                }

                else if (fish[i] > tree[mid]) {
                    if (fish[i] < tree[mid+1]) {
                        closest = min(abs(fish[i] - tree[mid+1]), abs(fish[i] - tree[mid]));
                        break;
                    }
                    left = mid + 1;
                }
            }
        } 

        total += max(dark[i] - closest, light[i]);
    }
    cout << total;

}
0