답안 #82836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82836 2018-11-02T01:36:13 Z luckyboy Go (COCI18_go) C++14
20 / 100
300 ms 86956 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,1,m)
        if (j != k)
        {
            if (j < k)
            {
                if (i - a[j+1].pos + a[j].pos >= 0)
                {
                    int add = i - a[j+1].pos + a[j].pos < 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[k].pos + a[j].pos < a[j].t;
                    Max(dp[i][j][k],dp[i - a[k].pos + a[j].pos][k][j+1] + add);
                }
            }
            else
            {
                if (i - a[j].pos - a[j-1].pos >= 0)
                {
                    int add = i - a[j].pos - a[j-1].pos < a[j].t ? a[j].c : 0;
                    Max(dp[i][j][k],dp[i][j-1][k] + add);
                }
                if (i - a[j].pos + a[k].pos >= 0)
                {
                    int add = i - a[j].pos + a[k].pos < a[j].t ? a[j].c : 0;
                    Max(dp[i][j][k],dp[i][k][j-1] + add);
                }
            }
        }
    int ans = -maxc;
    FOR(i,0,2000) ans = max(ans,dp[i][1][m]);
    write(ans);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10972 KB Output is correct
2 Correct 17 ms 16144 KB Output is correct
3 Incorrect 19 ms 19400 KB Output isn't correct
4 Incorrect 30 ms 24308 KB Output isn't correct
5 Incorrect 91 ms 49268 KB Output isn't correct
6 Incorrect 110 ms 57620 KB Output isn't correct
7 Incorrect 172 ms 65920 KB Output isn't correct
8 Incorrect 211 ms 74208 KB Output isn't correct
9 Incorrect 233 ms 82516 KB Output isn't correct
10 Incorrect 300 ms 86956 KB Output isn't correct