結果
| 問題 |
No.844 split game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-01 14:20:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 1,312 bytes |
| コンパイル時間 | 3,379 ms |
| コンパイル使用メモリ | 207,572 KB |
| 最終ジャッジ日時 | 2025-01-10 20:16:28 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 56 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:19:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
19 | int L,m,c; scanf("%d%d%d",&L,&m,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:21:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | rep(i,m) scanf("%d%d%d",&I[i].l,&I[i].r,&I[i].wt), I[i].r++;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
template<class T> struct interval{
T l,r;
int wt;
interval(){}
interval(const T& l,const T& r,int wt):l(l),r(r),wt(wt){}
bool operator<(const interval& I)const{ return make_tuple(r,l)<make_tuple(I.r,I.l); }
};
const long long INF=1LL<<61;
int main(){
int L,m,c; scanf("%d%d%d",&L,&m,&c);
vector<interval<int>> I(m);
rep(i,m) scanf("%d%d%d",&I[i].l,&I[i].r,&I[i].wt), I[i].r++;
vector<int> X={0,1,L+1};
rep(i,m){
X.emplace_back(I[i].l);
X.emplace_back(I[i].r);
}
sort(X.begin(),X.end());
X.erase(unique(X.begin(),X.end()),X.end());
rep(i,m){
I[i].l=lower_bound(X.begin(),X.end(),I[i].l)-X.begin();
I[i].r=lower_bound(X.begin(),X.end(),I[i].r)-X.begin();
}
sort(I.begin(),I.end());
int n=X.size(),idx=0;
// dp[i] = ([1, X[i]) に含まれる区間だけを考えて, X[i] の左に区切りを入れたときのスコアの最大値)
vector<lint> dp(n,-INF),dp_max(n,-INF);
dp[1]=0;
dp_max[1]=0;
for(int i=2;i<n;i++){
while(idx<m && I[idx].r==i){
dp[i]=max(dp[i],dp[I[idx].l]+I[idx].wt-(i<n-1?c:0));
dp[i]=max(dp[i],dp_max[I[idx].l-1]+I[idx].wt-(i<n-1?2*c:c));
idx++;
}
dp_max[i]=max(dp_max[i-1],dp[i]);
}
printf("%lld\n",dp_max[n-1]);
return 0;
}