//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
const int maxn = 22;
int n;
int a[maxn],b[maxn],dif[maxn];
int dp[(1<<maxn)];
bool hmm[(1<<maxn)];
bool check(int mask) {
bool tmp[maxn];
memset(tmp,false,sizeof(tmp));
rep(i,0,n) if ((mask>>i)&1) tmp[i] = true;
rep(i,0,n) {
ll cur = 0;
bool ok = true;
for (int j=i;j>=0 and ok;j--) {
cur*=2;
if (tmp[j]) cur += dif[j];
if (cur>0) ok = false;
}
for (int j = n-1;j>i and ok;j--) {
cur*=2;
if (tmp[j]) cur+= dif[j];
if (cur>0) ok = false;
}
if (cur==0 and ok) return true;
}
return false;
}
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie(0);
cin>>n;
rep(i,0,n) cin>>a[i]>>b[i],dif[i] = a[i]-b[i];
dp[0] = hmm[0] = 1;
rep(i,1,(1<<n)) {
dp[i] = hmm[i] = check(i);
// cout<<i<<" "<<check(i)<<endl;
}
rep(i,1,(1<<n))
for (int j = (i-1)&i;j>0 and dp[i]==0;j = (j-1)&i) {
if (dp[j]==1 and hmm[i^j]==1) {
dp[i] = 1;
break;
}
}
if (dp[(1<<n)-1]) cout<<"Yes";
else cout<<"No";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |