結果

問題 No.798 コレクション
ユーザー tnakao0123tnakao0123
提出日時 2019-03-21 16:29:50
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,314 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 89,124 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 05:24:49
合計ジャッジ時間 3,535 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 1 ms
4,348 KB
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |     scanf("%d%d", &bas[i].second, &bas[i].first);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 798.cc:  No.798 コレクション - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = MAX_N / 3;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;

/* global variables */

pii bas[MAX_N];
ll dp[MAX_N + 1][MAX_M + 1];

/* subroutines */

inline void setmin(ll &a, ll b) { if (a > b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &bas[i].second, &bas[i].first);
  sort(bas, bas + n, greater<pii>());

  int m = n / 3;
  for (int i = 0; i <= n; i++)
    fill(dp[i], dp[i] + m + 1, LINF);
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    int &ai = bas[i].second, &bi = bas[i].first;
    for (int j = 0; j <= i && j <= m; j++)
      if (dp[i][j] < LINF) {
	if (j < m) setmin(dp[i + 1][j + 1], dp[i][j]);
	setmin(dp[i + 1][j], dp[i][j] + ai + bi * (i - j));
      }
  }

  printf("%lld\n", dp[n][m]);
  return 0;
}
0