xiaofu15191's blog

By xiaofu15191, history, 19 months ago, In English

This is a code of AtCoder Typical 056.

#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);
		cout<<endl;
	}
	return 0;
}

It runs successfully when I'm using the compiler gcc.

However,I tried to solve this problem by submitting it in C++23 (Clang 16.0.6),and I failed for 5 times.

Every time I submitted it,the AtCoder returned me a CE.This is an example.

I also tried to compile this code by Clang on my local computer(Ubuntu 20.04 LTS,Clang 14,RAM 4GB).I waited for nearly 2 minutes,and all the programs which were running(MS Edge and VS Code) went crashed.

Can anyone tell my why could this happen?

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it