Submission #155301

# Submission time Handle Problem Language Result Execution time Memory
155301 2019-09-27T13:43:37 Z phillip Remittance (JOI19_remittance) C++14
0 / 100
1000 ms 376 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[9],b[9],s,n,dp[10][10][10][10][10][10][10];
void check(int x[7])
{
    for(int i=0;i<n;i++)
    {
        if(x[i]==b[i])continue;
        else return;
    }
    cout<<"YES";
    exit(0);
}
void bt(int x[7],int sm)
{
    if(sm<s)return;
    if(dp[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]])return;
    //for(int i=0;i<n;i++)cout<<x[i]<<" ";cout<<"\n";
    if(sm==s)
    {
        check(x);
        return;
    }
    for(int i=0;i<n;i++)
    {
        if(x[i]<=1)continue;
        x[i]-=2;
        x[(i+1)%n]++;
        bt(x,sm-1);
        x[(i+1)%n]--;
        x[i]+=2;
    }
    dp[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]][x[6]]=1;
    return;
}
int sm;
int main()
{
    cin>>n;
    while(1)sm++;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        sm+=a[i];
        s+=b[i];
    }
    bt(a,sm);
    cout<<"NO";
}

# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -