Submission #63463953
Source Code Expand
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
int n,s,a[110],b[110];
struct node
{
int first,second;
}f[105][100010][2];
void output(int i,int j,int k)
{
if(i>1) output(i-1,f[i][j][k].first,f[i][j][k].second);
if(k==0) cout<<"A";
else cout<<"B";
}
int main()
{
cin>>n>>s;
for(int i=1;i<=n;i++)
for(int j=0;j<=s;j++)
for(int k=0;k<2;k++)
f[i][j][k]=node{-1,-1};
cin>>a[1]>>b[1];
f[1][a[1]][0]=node{0,0};
f[1][b[1]][1]=node{0,0};
for(int i=2;i<=n;i++)
{
cin>>a[i]>>b[i];
for(int j=s;j>=a[i];j--)
{
if(f[i-1][j-a[i]][0].first!=-1) f[i][j][0]=node{j-a[i],0};
if(f[i-1][j-a[i]][1].first!=-1) f[i][j][0]=node{j-a[i],1};
}
for(int j=s;j>=b[i];j--)
{
if(f[i-1][j-b[i]][0].first!=-1) f[i][j][1]=node{j-b[i],0};
if(f[i-1][j-b[i]][1].first!=-1) f[i][j][1]=node{j-b[i],1};
}
}
if(f[n][s][0].first==-1&&f[n][s][1].first==-1) cout<<"Impossible"<<endl;
else
{
if(f[n][s][0].first!=-1) output(n,s,0);
else output(n,s,1);
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | 056 - Lucky Bag(★5) |
| User | xiaofu15191 |
| Language | C++ 23 (Clang 16.0.6) |
| Score | 0 |
| Code Size | 1094 Byte |
| Status | CE |
Compile Error
clang: error: unable to execute command: Killed clang: error: clang frontend command failed due to signal (use -v to see invocation) Ubuntu clang version 16.0.6 (++20230717114818+7cbf1a259152-1~exp1~20230717114903.110) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin clang: note: diagnostic msg: ******************** PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg: /tmp/Main-e66590.cpp clang: note: diagnostic msg: /tmp/Main-e66590.sh clang: note: diagnostic msg: ********************