結果

問題 No.710 チーム戦
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-07-01 08:34:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 3,000 ms
コード長 2,194 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 167,040 KB
実行使用メモリ 84,104 KB
最終ジャッジ日時 2023-09-13 16:31:52
合計ジャッジ時間 5,106 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
83,928 KB
testcase_01 AC 27 ms
83,932 KB
testcase_02 AC 90 ms
83,824 KB
testcase_03 AC 90 ms
83,844 KB
testcase_04 AC 92 ms
83,848 KB
testcase_05 AC 90 ms
83,928 KB
testcase_06 AC 90 ms
83,820 KB
testcase_07 AC 91 ms
83,848 KB
testcase_08 AC 91 ms
83,936 KB
testcase_09 AC 90 ms
83,920 KB
testcase_10 AC 90 ms
83,896 KB
testcase_11 AC 90 ms
84,104 KB
testcase_12 AC 91 ms
84,020 KB
testcase_13 AC 90 ms
83,932 KB
testcase_14 AC 90 ms
84,056 KB
testcase_15 AC 90 ms
83,812 KB
testcase_16 AC 90 ms
83,940 KB
testcase_17 AC 90 ms
83,860 KB
testcase_18 AC 90 ms
83,916 KB
testcase_19 AC 90 ms
83,956 KB
testcase_20 AC 91 ms
84,100 KB
testcase_21 AC 91 ms
83,828 KB
testcase_22 AC 86 ms
84,000 KB
testcase_23 AC 87 ms
83,852 KB
testcase_24 AC 86 ms
83,908 KB
testcase_25 AC 25 ms
83,876 KB
testcase_26 AC 24 ms
83,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/






int N, A[101], B[101];
int dp[101][204010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i] >> B[i];

    rep(i, 0, 101) rep(j, 0, 204010) dp[i][j] = inf;
    int base = 101010;
    dp[0][base] = 0;

    rep(i, 0, N) rep(j, 1010, 200010) {
        int d = j - base, dd;
        
        // get A
        dd = d - A[i];
        if (0 < d and dd < 0) chmin(dp[i + 1][dd + base], dp[i][j] + abs(dd));
        else if(d <= 0) chmin(dp[i + 1][dd + base], dp[i][j] + A[i]);
        else chmin(dp[i + 1][dd + base], dp[i][j]);

        // get B
        dd = d + B[i];
        if (0 <= d) chmin(dp[i + 1][dd + base], dp[i][j] + B[i]);
        else if (d < 0 and 0 <= dd) chmin(dp[i + 1][dd + base], dp[i][j] + dd);
        else chmin(dp[i + 1][dd + base], dp[i][j]);
    }

    int ans = inf;
    rep(j, 0, 204010) chmin(ans, dp[N][j]);
    cout << ans << endl;
}
0