답안 #82839

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82839 2018-11-02T02:12:45 Z luckyboy Go (COCI18_go) C++14
100 / 100
448 ms 86912 KB
/**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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 11000 KB Output is correct
2 Correct 16 ms 16064 KB Output is correct
3 Correct 27 ms 19360 KB Output is correct
4 Correct 27 ms 24396 KB Output is correct
5 Correct 105 ms 49284 KB Output is correct
6 Correct 132 ms 57476 KB Output is correct
7 Correct 250 ms 65816 KB Output is correct
8 Correct 293 ms 74256 KB Output is correct
9 Correct 321 ms 82452 KB Output is correct
10 Correct 448 ms 86912 KB Output is correct