Submission #17172850
Source Code Expand
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"
#define ll long long
#define int ll
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define pi pair<ll,ll>
#define node(a,b,c) mp(mp(a,b),c)
#define clr(x) memset(x,0,sizeof(x));
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
#define done(i) cout<<"done = "<<i<<endl;
#define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll inf=1e18;
const int mod=1e9+7;
const int M=205;
const int N=105;
int n;
int a[N],b[N];
int dp[M][N];
int yo[M];
int n2;
int work(int lft,int rgt)
{
int len=rgt-lft+1;
int ret=0;
int h=len/2;
for(int i=1,j=lft;i<=h;i++,j++)
{
yo[j]=1;
}
for(int i=1,j=rgt;i<=h;i++,j--)
{
yo[j]=2;
}
f(i,1,n)
{
if(a[i]!=-1 && b[i]!=-1)
{
if(a[i]>=lft && a[i]<=rgt && b[i]>rgt)return -1;
if(b[i]>=lft && b[i]<=rgt && a[i]<lft)return -1;
if(a[i]>=lft && a[i]<=rgt && b[i]>=lft && b[i]<=rgt)
{
int gap=b[i]-a[i];
if(gap!=h)return -1;
if(yo[a[i]]==1 && yo[b[i]]==2)
{
ret++;
yo[a[i]]=0;
yo[b[i]]=0;
}
else
{
return -1;
}
}
}
else if(a[i]!=-1)
{
if(a[i]>=lft && a[i]<=rgt)
{
if(yo[a[i]]!=1)return -1;
int nxt=a[i]+h;
if(nxt>rgt)return -1;
if(yo[nxt]!=2)return -1;
ret++;
yo[a[i]]=0;
yo[nxt]=0;
}
}
else if(b[i]!=-1)
{
if(b[i]>=lft && b[i]<=rgt)
{
if(yo[b[i]]!=2)return -1;
int nxt=b[i]-h;
if(nxt<lft)return -1;
if(yo[nxt]!=1)return -1;
ret++;
yo[b[i]]=0;
yo[nxt]=0;
}
}
}
f(i,lft,rgt)
{
if(yo[i]==1)ret++;
}
return ret;
}
int solve(int pos,int baki)
{
if(pos>n2)
{
if(baki==0)return 1LL;
else return 0LL;
}
int &ret=dp[pos][baki];
if(ret!=(-1))return ret;
ret=0;
for(int j=pos;j<=n2;j++)
{
int len=j-pos+1;
if(len%2)continue;
int c=work(pos,j);
if(c!=-1)
{
bool flag=solve(j+1,baki-c);
if(flag==true)ret=true;
}
}
return ret;
}
main()
{
fast
memset(dp,-1,sizeof dp);
set<int>s;
int chk=0,flag=0;
cin>>n;
n2=2*n;
f(i,1,n)
{
cin>>a[i]>>b[i];
if(a[i]!=-1)s.insert(a[i]),chk++;
if(b[i]!=-1)s.insert(b[i]),chk++;
if(b[i]!=-1 && b[i]==1)flag=1;
if(a[i]!=-1 && a[i]==n2)flag=1;
if(a[i]!=-1 && b[i]!=-1)
{
if(a[i]>=b[i])flag=1;
}
}
if(flag==1)
{
cout<<"No\n";return 0;
}
if(s.size()!=chk)
{
cout<<"No\n";return 0;
}
int ses=solve(1,n);
if(ses)
{
cout<<"Yes\n";
}
else
{
cout<<"No\n";
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Fair Elevator |
| User | Ahasan_1999 |
| Language | C++ (GCC 9.2.1) |
| Score | 600 |
| Code Size | 4328 Byte |
| Status | AC |
| Exec Time | 8 ms |
| Memory | 3764 KiB |
Compile Error
./Main.cpp:123:7: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
123 | main()
| ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:149:16: warning: comparison of integer expressions of different signedness: ‘std::set<long long int>::size_type’ {aka ‘long unsigned int’} and ‘long long int’ [-Wsign-compare]
149 | if(s.size()!=chk)
| ~~~~~~~~^~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 8 ms | 3672 KiB |
| 02.txt | AC | 3 ms | 3664 KiB |
| 03.txt | AC | 2 ms | 3596 KiB |
| 04.txt | AC | 2 ms | 3672 KiB |
| 05.txt | AC | 3 ms | 3624 KiB |
| 06.txt | AC | 2 ms | 3740 KiB |
| 07.txt | AC | 4 ms | 3760 KiB |
| 08.txt | AC | 2 ms | 3696 KiB |
| 09.txt | AC | 2 ms | 3600 KiB |
| 10.txt | AC | 7 ms | 3720 KiB |
| 11.txt | AC | 2 ms | 3752 KiB |
| 12.txt | AC | 2 ms | 3720 KiB |
| 13.txt | AC | 2 ms | 3748 KiB |
| 14.txt | AC | 2 ms | 3664 KiB |
| 15.txt | AC | 2 ms | 3628 KiB |
| 16.txt | AC | 2 ms | 3676 KiB |
| 17.txt | AC | 2 ms | 3688 KiB |
| 18.txt | AC | 2 ms | 3740 KiB |
| 19.txt | AC | 2 ms | 3744 KiB |
| 20.txt | AC | 5 ms | 3748 KiB |
| 21.txt | AC | 2 ms | 3580 KiB |
| 22.txt | AC | 2 ms | 3756 KiB |
| 23.txt | AC | 6 ms | 3688 KiB |
| 24.txt | AC | 2 ms | 3660 KiB |
| 25.txt | AC | 7 ms | 3744 KiB |
| 26.txt | AC | 2 ms | 3592 KiB |
| 27.txt | AC | 3 ms | 3736 KiB |
| 28.txt | AC | 4 ms | 3660 KiB |
| 29.txt | AC | 3 ms | 3644 KiB |
| 30.txt | AC | 3 ms | 3672 KiB |
| 31.txt | AC | 2 ms | 3744 KiB |
| 32.txt | AC | 2 ms | 3672 KiB |
| 33.txt | AC | 2 ms | 3740 KiB |
| 34.txt | AC | 2 ms | 3720 KiB |
| 35.txt | AC | 2 ms | 3744 KiB |
| 36.txt | AC | 3 ms | 3756 KiB |
| 37.txt | AC | 2 ms | 3756 KiB |
| 38.txt | AC | 2 ms | 3764 KiB |
| 39.txt | AC | 3 ms | 3656 KiB |
| 40.txt | AC | 2 ms | 3668 KiB |
| 41.txt | AC | 2 ms | 3628 KiB |
| 42.txt | AC | 2 ms | 3660 KiB |
| 43.txt | AC | 3 ms | 3744 KiB |
| s1.txt | AC | 2 ms | 3660 KiB |
| s2.txt | AC | 2 ms | 3724 KiB |
| s3.txt | AC | 2 ms | 3660 KiB |