/ tabris /

记录详情

Time Exceeded

/in/foo.cc: In function 'int dfs(int, int, ll, int)':
/in/foo.cc:53:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 状态 耗时 内存占用
#1 Wrong Answer 2ms 956.0 KiB
#2 Wrong Answer 2ms 964.0 KiB
#3 Wrong Answer 12ms 1016.0 KiB
#4 Wrong Answer 1ms 848.0 KiB
#5 Wrong Answer 399ms 1.262 MiB
#6 Wrong Answer 371ms 1.328 MiB
#7 Time Exceeded ≥3001ms ≥1.457 MiB
#8 Time Exceeded ≥3005ms ≥2.312 MiB
#9 Time Exceeded ≥3000ms ≥3.309 MiB
#10 Time Exceeded ≥3005ms ≥3.312 MiB

代码

#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
ll a[10005][4],b[10005][4];
ll ans=-111112;
map<ll,int>q;
map<ll,int>qq;
int n,m;
int dfs(int x,int y,ll cnt,int t)
{
    if(qq[x*1000000000+t*10+y]!=0&&q[x*1000000000+t*10+y]>=cnt)
        return 0;
    else
        q[x*1000000000+t*10+y]=cnt,qq[x*1000000000+t*10+y]=1;
    int yb=y;
    if(x==n)
    {
        //cout<<cnt<<' ';
        ans=max(ans,cnt);return 0;
    }
    for(int i=1;i<=3;i++)
    {
        yb=y+i-2;
        if(yb>=1&&yb<=3)
        {
            if(t!=0)
            {
                t--;
                dfs(x+1,yb,cnt-a[x+1][yb],t);
                t++;
            }
            else
            {
                if(a[x+1][yb]==0)
                {
                    t=m;
                    dfs(x+1,yb,cnt+a[x+1][yb],t);
                    t=0;
                }
                else
                {
                    dfs(x+1,yb,cnt+a[x+1][yb],0);
                }
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    cin>>n>>m;
    q.clear();qq.clear();
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=3; j++)
        {
            cin>>a[i][j];
        }
    } ans=a[0][2];dfs(0,2,a[0][2],0);
    cout<<ans<<endl;
}

信息

递交者
类型
递交
语言
C++
递交时间
2019-06-10 12:48:29
评测时间
2019-06-10 12:48:29
评测机
分数
0
总耗时
≥12802ms
峰值内存
≥3.312 MiB