Submission #82839

#TimeUsernameProblemLanguageResultExecution timeMemory
82839luckyboyGo (COCI18_go)C++14
100 / 100
448 ms86912 KiB
/**Lucky Boy**/ #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) #define pb push_back #define mp make_pair #define F first #define S second #define maxc 1000000007 #define maxn 105 #define maxm 2005 #define pii pair <int,int> #define Task "Go" template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;} template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);} template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');} template <typename T> inline void writeln(T x){write(x);putchar('\n');} using namespace std; int n,st,m,dp[maxm][maxn][maxn]; struct house { int pos,c,t; }a[maxn]; void Max(int &x,int y) {if (x < y) x = y;}; int main() { //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //freopen(Task".inp", "r",stdin); //freopen(Task".out", "w",stdout); read(n),read(st),read(m); FOR(i,1,m) { read(a[i].pos); read(a[i].c); read(a[i].t); } FOR(i,0,2000) FOR(j,1,m) FOR(k,1,m) dp[i][j][k] = -maxc; FOR(i,1,m) dp[abs(st - a[i].pos)][i][i] = abs(st - a[i].pos) < a[i].t ? a[i].c : 0; FOR(i,1,2000) FOR(j,1,m) FOR(k,j+1,m) { if (i - a[j+1].pos + a[j].pos >= 0) { int add = i < a[j].t ? a[j].c : 0; Max(dp[i][j][k],dp[i - a[j+1].pos + a[j].pos][j+1][k] + add); } if (i - a[k].pos + a[j].pos >= 0) { int add = i < a[j].t ? a[j].c : 0; Max(dp[i][j][k],dp[i - a[k].pos + a[j].pos][k][j+1] + add); } if (i - a[k].pos + a[k-1].pos >= 0) { int add = i < a[k].t ? a[k].c : 0; Max(dp[i][k][j],dp[i - a[k].pos + a[k-1].pos][k-1][j] + add); } if (i - a[k].pos + a[j].pos >= 0) { int add = i < a[k].t ? a[k].c : 0; Max(dp[i][k][j],dp[i - a[k].pos + a[j].pos][j][k-1] + add); } } int ans = -maxc; FOR(i,0,2000) ans = max(ans,max(dp[i][1][m],dp[i][m][1])); write(ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...