QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#594080 | #7786. Graft and Transplant | argtarg | WA | 1ms | 3524kb | C++20 | 1.2kb | 2024-09-27 18:57:52 | 2024-09-27 18:57:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pii pair<int, int>
void solve();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--)solve();
return 0;
}
const int mod = 1e9 + 7;
void solve() {
int x,y,p,q;
cin>>x>>y>>p>>q;
if(x<=p) {
cout<<1<<endl;
return;
}
vector<vector<int>>dp(x+1,vector<int>(y+1,1e4));
dp[x][y]=-1;
int ans=1e4;
for(int i=x;i>=0;i--) {
for(int j=y;j>=0;j--) {
int a=x-i,b=y-j;
if(i+q<j&&i!=x||a+q<b&&a!=0)continue;
// if(i==2&&j==4)cout<<dp[i][j]<<endl;
if(i<=p)ans=min(ans,dp[i][j]+2);
for(int xx=0;xx<=i;xx++) {
for(int yy=0;yy<=j;yy++) {
if(xx>p-yy)continue;
dp[i-xx][j-yy]=min(dp[i-xx][j-yy],dp[i][j]+2);
}
}
}
}
ans=min(*min_element(dp[0].begin(),dp[0].end()),ans);
if(p/2+p>=x&&x+p+q>=y) {
ans=min(5ll,ans);
}
if(ans!=1e4)cout<<ans<<endl;
else cout<<-1<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3524kb
input:
4 1 2 2 3 3 4
output:
3
result:
wrong answer 1st words differ - expected: 'Alice', found: '3'