結果

問題 No.798 コレクション
コンテスト
ユーザー tempura_pp
提出日時 2019-03-15 21:43:13
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,117 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 914 ms
コンパイル使用メモリ 160,000 KB
実行使用メモリ 34,884 KB
最終ジャッジ日時 2026-05-24 05:09:36
合計ジャッジ時間 2,211 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:31:7: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   31 |         ll a[n],b[n];
      |              ^
main.cpp:31:7: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:29:6: note: declared here
   29 |         int n;
      |             ^
main.cpp:31:12: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   31 |         ll a[n],b[n];
      |                   ^
main.cpp:31:12: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:29:6: note: declared here
   29 |         int n;
      |             ^
main.cpp:38:13: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   38 |         ll dp[n+1][n+1];
      |                    ^~~
main.cpp:38:13: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:29:6: note: declared here
   29 |         int n;
      |             ^
main.cpp:38:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   38 |         ll dp[n+1][n+1];
      |               ^~~
main.cpp:38:8: note: read of non-const variable 'n' is not allowed in a constant expression
main.cpp:29:6: note: declared here
   29 |         int n;
      |             ^
4 warnings generated.

ソースコード

diff #
raw source code

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
	int n;
	cin>>n;
	ll a[n],b[n];
	rep(i,n)cin>>a[i]>>b[i];
	vector<int> ord(n);
	iota(ord.begin(),ord.end(),0);
	sort(ord.begin(),ord.end(),[&](auto x,auto y){
		return b[x]==b[y] ? a[x]>a[y] : b[x]>b[y];
		});
	ll dp[n+1][n+1];
	rep(i,n+1)rep(j,n+1)dp[i][j]=longinf;
	dp[0][0]=0;
	rep(i,n)rep(j,n){
		int idx=ord[i];
		dp[i+1][j+1]=min(dp[i][j]+a[idx]+b[idx]*j,dp[i+1][j+1]);
		dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
		dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j+1]);
	}
	int m;
	if(n%3==0)m=n/3*2;
	if(n%3==1)m=n/3*2+1;
	if(n%3==2)m=n/3*2+2;
	cout<<dp[n][m]<<endl;
	return 0;
}
0