QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#432526#8776. Not Another Constructive!ucup-team3772#AC ✓33ms61484kbC++1415.2kb2024-06-07 10:21:472024-06-07 10:21:47

Judging History

你现在查看的是最新测评结果

  • [2024-06-07 10:21:47]
  • 评测
  • 测评结果:AC
  • 用时:33ms
  • 内存:61484kb
  • [2024-06-07 10:21:47]
  • 提交

answer

/*
  author: honglan0301
  Sexy_goodier _ xiaoqing
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <queue>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <bitset>
#include <assert.h>
using namespace std;

//namespace Fread{const int SIZE=1<<20;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return*S++;}}using namespace Fread;namespace Fwrite{const int SIZE=1<<20;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}using namespace Fwrite;
//#define getchar Fread::getchar
//#define putchar Fwrite::putchar

namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl//;fflush(stdout)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define ll long long
#define ull unsigned long long
#define mod 998244353
#define G 3
#define Gi 332748118
mt19937 rnd(time(0));
mt19937_64 rndl(time(0));

int ksm(int x,int k) {int na=1; for(int i=1;i<=k;i<<=1) {if(i&k) na=na*x%mod; x=x*x%mod;} return na;}
int gcd(int x,int y) {return !y?x:gcd(y,x%y);}
void exgcd(int u,int v,ll &x,ll &y) {if(!v) return x=1,y=0,void(); exgcd(v,u%v,y,x); y-=u/v*x;}
void CRTmerge(ll la,ll lb,ll&na,ll&nb){ll g=gcd(la,na),x,y;exgcd(la,na,x,y);ll dd=(nb-lb)/g;x*=dd;na=la*na/g;nb=((x*la+lb)%na+na)%na;}

struct MF
{
	#define N 1
	#define NN 1
	#define M 1
	struct edge{int son,val,next;}edge[M];
	int cnt=1,head[N],nowb[N],dis[N],ff[NN],pre[NN],s,t;
	void adde(int x,int y,int z)
	{
		edge[++cnt]={y,z,head[x]}; head[x]=cnt;
		edge[++cnt]={x,0,head[y]}; head[y]=cnt;
	}
	void clear(int n)
	{
		for(int i=0;i<=cnt;i++) edge[i]={0,0,0};
		for(int i=0;i<=n;i++) head[i]=nowb[i]=dis[i]=0; cnt=1;
	}
	queue<int>Q;bool bfs(){memset(dis,127,sizeof(dis));dis[s]=0;Q.push(s);while(!Q.empty()){int nr=Q.front();Q.pop();for(int i=head[nr];i>0;i=edge[i].next){if(edge[i].val&&dis[nr]+1<dis[edge[i].son])dis[edge[i].son]=dis[nr]+1,Q.push(edge[i].son);}}return dis[t]<1000000000;}
	int bfs2(){memset(ff,0,sizeof(ff));ff[s]=1000000000;pre[s]=-1;Q.push(s);while(!Q.empty()){int nr=Q.front();Q.pop();for(int i=head[nr];i>0;i=edge[i].next){if(!ff[edge[i].son]&&edge[i].val){ff[edge[i].son]=min(edge[i].val,ff[nr]);pre[edge[i].son]=i;Q.push(edge[i].son);}}if(ff[t])break;}while(!Q.empty())Q.pop();return ff[t];}int EK(){int na=0;while(bfs2()){na+=ff[t];for(int j=pre[t];j>0;j=pre[edge[j^1].son])edge[j].val-=ff[t],edge[j^1].val+=ff[t];}return na;}
	int dfs(int x,int nfl){if(x==t)return nfl;int nuse=0;for(int i=nowb[x];i>0;i=edge[i].next){nowb[x]=i;if(edge[i].val&&dis[x]+1==dis[edge[i].son]){int flw=dfs(edge[i].son,min(edge[i].val,nfl-nuse));edge[i].val-=flw;edge[i^1].val+=flw;nuse+=flw;if(nuse==nfl)break;}}return nuse;}
	int dinic(){int maxflow=0;while(bfs()){memcpy(nowb,head,sizeof(head));maxflow+=dfs(s,1000000000);}return maxflow;}
	#undef N
	#undef NN
	#undef M
}MF;

struct MCMF
{
	#define N 1
	#define M 1
	struct edge
	{
		int son,val,fey,next;
	}edge[M];
	int head[N],cnt=1,nowb[N],dis[N],dep[N],maxflow,mincost,s,t;
	void adde(int x,int y,int z,int w)
	{
		edge[++cnt]={y,z,w,head[x]}; head[x]=cnt;
		edge[++cnt]={x,0,-w,head[y]}; head[y]=cnt;
	}
	void clear(int n)
	{
		for(int i=0;i<=cnt;i++) edge[i]={0,0,0};
		for(int i=0;i<=n;i++) head[i]=nowb[i]=dis[i]=dep[i]=0; cnt=1;
	}
	queue<int>Q;bool spfa(){memset(dis,127,sizeof(dis));dis[s]=dep[s]=0;Q.push(s);while(!Q.empty()){int nr=Q.front();Q.pop();for(int i=head[nr];i>0;i=edge[i].next){if(edge[i].val&&dis[nr]+edge[i].fey<dis[edge[i].son]){dis[edge[i].son]=dis[nr]+edge[i].fey;dep[edge[i].son]=dep[nr]+1;Q.push(edge[i].son);}}}return dis[t]<1000000000000;}int dfs(int x,int nfl){if(x==t)return mincost+=nfl*dis[t],nfl;int nuse=0;for(int i=nowb[x];i>0;i=edge[i].next){nowb[x]=i;if(edge[i].val&&dis[x]+edge[i].fey==dis[edge[i].son]&&dep[x]+1==dep[edge[i].son]){int flw=dfs(edge[i].son,min(edge[i].val,nfl-nuse));edge[i].val-=flw;edge[i^1].val+=flw;nuse+=flw;if(nuse==nfl)break;}}return nuse;}
	pair<int,int>dinic(){maxflow=mincost=0;while(spfa()){memcpy(nowb,head,sizeof(nowb));maxflow+=dfs(s,1000000000);}return mp(maxflow,mincost);}
	#undef N
	#undef M
}MCMF;

struct SA
{
	#define N 1
	#define M 135
	int s[N],rk[N],sa[N],lrk[N],buc[N],id[N],ht[N];
	void clear(int n) {memset(buc,0,sizeof(buc[0])*(n+3));}
	void build(int n){int m=M,p=0;for(int i=1;i<=n;i++)buc[rk[i]=s[i]]++;for(int i=1;i<=M;i++)buc[i]+=buc[i-1];for(int i=1;i<=n;i++)sa[buc[rk[i]]--]=i;for(int w=1;w<=n;w<<=1){for(int i=n-w+1;i<=n;i++)id[++p]=i;for(int i=1;i<=n;i++)if(sa[i]>w)id[++p]=sa[i]-w;memcpy(lrk,rk,sizeof(rk[0])*(n+3));memset(buc,0,sizeof(buc[0])*(m+3));p=0;for(int i=1;i<=n;i++)buc[lrk[i]]++;for(int i=1;i<=m;i++)buc[i]+=buc[i-1];for(int i=n;i>=1;i--)sa[buc[lrk[id[i]]]--]=id[i];for(int i=1;i<=n;i++)rk[sa[i]]=(lrk[sa[i]]==lrk[sa[i-1]]&&lrk[sa[i]+w]==lrk[sa[i-1]+w])?p:++p;m=p;p=0;if(m==n)break;}for(int i=1,k=0;i<=n;i++){k--;if(k<0)k++;while(s[i+k]==s[sa[rk[i]-1]+k])k++;ht[rk[i]]=k;}}
	#undef N
	#undef M
}SA;

struct LC
{
	#define N 1
	int n,x[N],y[N],F[N],lf[N],nf[N];
	void init(){lf[0]=1;for(int i=1;i<=n;i++){for(int j=n;j>=0;j--)lf[j]=(lf[j]*(mod-x[i])+((j>0)?lf[j-1]:0))%mod;}for(int i=1;i<=n;i++){int prd=1;for(int j=1;j<=n;j++)if(i!=j)prd=prd*(x[i]-x[j]+mod)%mod;prd=ksm(prd,mod-2);for(int j=n;j>=0;j--)nf[j]=(lf[j+1]+x[i]*nf[j+1])%mod;for(int j=0;j<=n;j++)F[j]=(F[j]+y[i]*nf[j]%mod*prd)%mod;}}
	int solve(int k){int na=0;for(int i=n;i>=0;i--)na=(na*k+F[i])%mod;return na;}
	#undef N
}LC;

struct LO
{
	struct node
	{
		int cntu,cntr,sums;
		friend node operator+(node x,node y)
		{
			node z; 
			z.cntu=(x.cntu+y.cntu)%mod; z.cntr=(x.cntr+y.cntr)%mod;
			z.sums=(x.sums+y.sums+x.cntu*y.cntr)%mod; return z;
		}
	};
	node getk() {node x; x.cntu=x.cntr=x.sums=0; return x;}
	node getr() {node x; x.cntu=x.sums=0; x.cntr=1; return x;}
	node getu() {node x; x.cntu=1; x.cntr=x.sums=0; return x;}
	node ksm(node x,int k){node na=getk();for(int i=1;i<=k;i<<=1){if(i&k)na=na+x;x=x+x;}return na;}node solve(int p,int r,int q,int x,node nu,node nr){if(!x)return getk();if(p*x+r<q)return ksm(nr,x);if(p>=q||r>=q)return ksm(nu,r/q)+solve(p%q,r%q,q,x,nu,ksm(nu,p/q)+nr);int m=(p*x+r)/q;return ksm(nr,(q-r-1)/p)+nu+solve(q,(q-r-1)%p,p,m-1,nr,nu)+ksm(nr,x-(q*m-r-1)/p);}
}LO;

struct NTT
{
	#define N 1
	int rv[N],lim,L;
	void init(int n) {lim=1,L=0; while(lim<=n) lim<<=1,L++; for(int i=0;i<lim;i++) rv[i]=(rv[i>>1]>>1)|((i&1)<<L-1);}
	void work(int x[],int flag){for(int i=0;i<lim;i++)if(i<rv[i])swap(x[i],x[rv[i]]);for(int len=1;len<lim;len<<=1){int w=ksm((flag==1)?G:Gi,(mod-1)/(len<<1));for(int j=0;j<lim;j+=(len<<1)){int nw=1;for(int k=0;k<len;k++){int xx=x[j|k],yy=nw*x[j|k|len]%mod;x[j|k]=(xx+yy)%mod;x[j|k|len]=(xx-yy+mod)%mod;nw=nw*w%mod;}}}if(flag==-1){int iv=ksm(lim,mod-2);for(int i=0;i<lim;i++)x[i]=x[i]*iv%mod;}}
	#undef N
}NTT;

struct FWT
{
	void AND(int x[],int n,int flag){for(int len=1;len<(1<<n);len<<=1){for(int j=0;j<(1<<n);j+=(len<<1)){for(int k=0;k<len;k++){if(flag==1)x[j|k]=(x[j|k]+x[j|k|len])%mod;else x[j|k]=(x[j|k]-x[j|k|len]+mod)%mod;}}}}
	void OR(int x[],int n,int flag){for(int len=1;len<(1<<n);len<<=1){for(int j=0;j<(1<<n);j+=(len<<1)){for(int k=0;k<len;k++){if(flag==1)x[j|k|len]=(x[j|k|len]+x[j|k])%mod;else x[j|k|len]=(x[j|k|len]-x[j|k]+mod)%mod;}}}}
	void XOR(int x[],int n,int flag){for(int len=1;len<(1<<n);len<<=1){for(int j=0;j<(1<<n);j+=(len<<1)){for(int k=0;k<len;k++){int xx=x[j|k],yy=x[j|k|len];x[j|k]=(xx+yy)%mod;x[j|k|len]=(xx-yy+mod)%mod;}}}if(flag==-1){int iv=ksm((1<<n),mod-2);for(int i=0;i<(1<<n);i++)x[i]=x[i]*iv%mod;}}
}FWT;

/*struct PT
{
	int x,y;
	bool operator<(const PT &rs) {return x!=rs.x?x<rs.x:y<rs.y;}
	bool operator>(const PT &rs) {return x!=rs.x?x>rs.x:y>rs.y;}
	bool operator==(const PT &rs) {return x==rs.x&&y==rs.y;}
	PT operator+(const PT &rs) {return {x+rs.x,y+rs.y};}
	PT operator-(const PT &rs) {return {x-rs.x,y-rs.y};}
}nl,stk[1];
int arg(PT xx) {return (int)xx.x*xx.x+(int)xx.y*xx.y;}
int cross(PT xx,PT yy) {return (int)xx.x*yy.y-(int)xx.y*yy.x;}
int dot(PT xx,PT yy) {return (int)xx.x*yy.x+(int)xx.y*yy.y;}*/

struct PT
{
	double x,y;
	bool operator<(const PT &rs) {return x!=rs.x?x<rs.x:y<rs.y;}
	bool operator>(const PT &rs) {return x!=rs.x?x>rs.x:y>rs.y;}
	bool operator==(const PT &rs) {return x==rs.x&&y==rs.y;}
	PT operator+(const PT &rs) {return {x+rs.x,y+rs.y};}
	PT operator-(const PT &rs) {return {x-rs.x,y-rs.y};}
	PT operator*(const double rs) {return {x*rs,y*rs};}
	PT operator/(const double rs) {return {x/rs,y/rs};}
}nl,STK[1];
double arg(PT xx) {return xx.x*xx.x+xx.y*xx.y;}
double len(PT xx) {return sqrt(arg(xx));}
double cross(PT xx,PT yy) {return xx.x*yy.y-xx.y*yy.x;}
double dot(PT xx,PT yy) {return xx.x*yy.x+xx.y*yy.y;}
double cdis(PT xx,PT yy) {return sqrt(arg(xx-yy));}
PT rotate(PT xx,double rad) {return {xx.x*cos(rad)+xx.y*sin(rad),-xx.x*sin(rad)+xx.y*cos(rad)};}

bool cmpPT(PT xx,PT yy) {return cross(xx-nl,yy-nl)!=0?cross(xx-nl,yy-nl)<0:arg(xx-nl)<arg(yy-nl);}
void init(vector<PT> &xx)
{
	sort(xx.begin(),xx.end()); 
	xx.erase(unique(xx.begin(),xx.end()),xx.end());
	int top;
	nl=xx[top=0]; sort(xx.begin()+1,xx.end(),cmpPT);
	for(auto i:xx)
	{
		while(top>=2&&cross(i-STK[top],STK[top]-STK[top-1])<=0) top--;
		STK[++top]=i;
	}
	xx.clear(); for(int i=1;i<=top;i++) xx.pb(STK[i]);
}
void init2(vector<PT> &xx)
{
	int top; nl=xx[top=0];
	for(auto i:xx)
	{
		while(top>=2&&cross(i-STK[top],STK[top]-STK[top-1])<=0) top--;
		STK[++top]=i;
	}
	xx.clear(); for(int i=1;i<=top;i++) xx.pb(STK[i]);
}
vector<PT> merge(vector<PT> xx,vector<PT> yy)
{
	vector<PT> na,nx,ny; na.pb(xx[0]+yy[0]); int L=xx.size(),R=yy.size(),cntl=0,cntr=0;
	for(int i=0;i<L;i++) nx.pb(xx[(i+1)%L]-xx[i]); for(int i=0;i<R;i++) ny.pb(yy[(i+1)%R]-yy[i]);
	while(cntl<L&&cntr<R) {int cc=cross(nx[cntl],ny[cntr]); na.pb(na.back()+((cc<0||!cc&&nx[cntl]>ny[cntr])?nx[cntl++]:ny[cntr++]));}
	while(cntl+1<L) na.pb(na.back()+nx[cntl++]);
	while(cntr+1<R) na.pb(na.back()+ny[cntr++]); return na;
}

int n,k;
bitset <2501> dp[41][41][401];
char s[45];

void solve(int i,int j,int p,int k)
{
	if(!i) {return;}
	if(s[i]=='N'||s[i]=='?')
	{
		if(j>=1&&dp[i-1][j-1][p][k])
		{
			solve(i-1,j-1,p,k); cout<<"N"; return;
		}
	}
	if(s[i]=='A'||s[i]=='?')
	{
		if(p>=j&&dp[i-1][j][p-j][k])
		{
			solve(i-1,j,p-j,k); cout<<"A"; return;
		}
	}
	if(s[i]=='C'||s[i]=='?')
	{
		if(k>=p&&dp[i-1][j][p][k-p])
		{
			solve(i-1,j,p,k-p); cout<<"C"; return;
		}
	}
	if(s[i]!='N'&&s[i]!='A'&&s[i]!='C')
	{
		if(dp[i-1][j][p][k])
		{
			solve(i-1,j,p,k); if(s[i]=='?') cout<<"B"; else cout<<s[i]; return;
		}
	}
}

signed main()
{
	cin>>n>>k>>(s+1);
	dp[0][0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='N'||s[i]=='?')
		{
			for(int j=1;j<=i;j++)
			{
				for(int p=0;p<=(i/2)*((i+1)/2);p++)
				{
					dp[i][j][p]|=dp[i-1][j-1][p];
				}
			}
		}
		if(s[i]=='A'||s[i]=='?')
		{
			for(int j=0;j<=i;j++)
			{
				for(int p=j;p<=(i/2)*((i+1)/2);p++)
				{
					dp[i][j][p]|=dp[i-1][j][p-j];
				}
			}
		}
		if(s[i]=='C'||s[i]=='?')
		{
			for(int j=0;j<=i;j++)
			{
				for(int p=0;p<=(i/2)*((i+1)/2);p++)
				{
					dp[i][j][p]|=dp[i-1][j][p]<<p;
				}
			}
		}
		if(s[i]!='N'&&s[i]!='A'&&s[i]!='C')
		{
			for(int j=0;j<=i;j++)
			{
				for(int p=0;p<=(i/2)*((i+1)/2);p++)
				{
					dp[i][j][p]|=dp[i-1][j][p];
				}
			}
		}
	}
	for(int j=0;j<=n;j++)
	{
		for(int p=0;p<=(n/2)*((n+1)/2);p++)
		{
			if(dp[n][j][p][k])
			{
				solve(n,j,p,k); return 0;
			}
		}
	}
	cout<<"-1"<<endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 10028kb

input:

22 2
N??A??????C???????????

output:

NCCABBBBBBCBBBBBBBBBBC

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 6940kb

input:

18 0
COUNTINGSATELLITES

output:

COUNTINGSATELLITES

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

1 0
?

output:

A

result:

ok correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

1 0
N

output:

N

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

1 0
X

output:

X

result:

ok correct

Test #7:

score: 0
Accepted
time: 0ms
memory: 3704kb

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

2 0
??

output:

AA

result:

ok correct

Test #11:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

2 0
N?

output:

NC

result:

ok correct

Test #12:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

2 0
?C

output:

AC

result:

ok correct

Test #13:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

2 1
N?

output:

-1

result:

ok correct

Test #14:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3 1
??C

output:

NAC

result:

ok correct

Test #19:

score: 0
Accepted
time: 0ms
memory: 3928kb

input:

3 1
NA?

output:

NAC

result:

ok correct

Test #20:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

3 1
N?C

output:

NAC

result:

ok correct

Test #21:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

3 1
?AC

output:

NAC

result:

ok correct

Test #22:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

4 1
????

output:

ANAC

result:

ok correct

Test #23:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

4 1
X???

output:

XNAC

result:

ok correct

Test #24:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4 1
???Z

output:

NACZ

result:

ok correct

Test #25:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

4 1
?AA?

output:

-1

result:

ok correct

Test #26:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

4 1
N???

output:

NCAC

result:

ok correct

Test #27:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

4 1
?N??

output:

ANAC

result:

ok correct

Test #28:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

4 1
??N?

output:

NANC

result:

ok correct

Test #29:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

4 1
???N

output:

NACN

result:

ok correct

Test #30:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

4 1
A???

output:

ANAC

result:

ok correct

Test #31:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

4 1
?A??

output:

NABC

result:

ok correct

Test #32:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

4 1
??A?

output:

ANAC

result:

ok correct

Test #33:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

4 1
???A

output:

NACA

result:

ok correct

Test #34:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

4 1
C???

output:

CNAC

result:

ok correct

Test #35:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

4 1
?C??

output:

NCAC

result:

ok correct

Test #36:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

4 1
??C?

output:

NACB

result:

ok correct

Test #37:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

4 1
???C

output:

ANAC

result:

ok correct

Test #38:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

5 4
?????

output:

NAACC

result:

ok correct

Test #39:

score: 0
Accepted
time: 0ms
memory: 3996kb

input:

6 14
??????

output:

-1

result:

ok correct

Test #40:

score: 0
Accepted
time: 0ms
memory: 3900kb

input:

7 14
???????

output:

-1

result:

ok correct

Test #41:

score: 0
Accepted
time: 1ms
memory: 3924kb

input:

8 43
????????

output:

-1

result:

ok correct

Test #42:

score: 0
Accepted
time: 1ms
memory: 4232kb

input:

9 55
?????????

output:

-1

result:

ok correct

Test #43:

score: 0
Accepted
time: 1ms
memory: 4504kb

input:

10 112
??????????

output:

-1

result:

ok correct

Test #44:

score: 0
Accepted
time: 1ms
memory: 4608kb

input:

11 110
???????????

output:

-1

result:

ok correct

Test #45:

score: 0
Accepted
time: 1ms
memory: 4800kb

input:

12 4
????????????

output:

AAAAAANACCCC

result:

ok correct

Test #46:

score: 0
Accepted
time: 1ms
memory: 4972kb

input:

13 193
?????????????

output:

-1

result:

ok correct

Test #47:

score: 0
Accepted
time: 1ms
memory: 5260kb

input:

14 91
??????????????

output:

NNNANAAACACCCC

result:

ok correct

Test #48:

score: 0
Accepted
time: 2ms
memory: 5612kb

input:

15 15
???????????????

output:

NACCCCCCCCCACCC

result:

ok correct

Test #49:

score: 0
Accepted
time: 2ms
memory: 5680kb

input:

16 261
????????????????

output:

-1

result:

ok correct

Test #50:

score: 0
Accepted
time: 2ms
memory: 6296kb

input:

17 514
?????????????????

output:

-1

result:

ok correct

Test #51:

score: 0
Accepted
time: 3ms
memory: 6936kb

input:

18 678
??????????????????

output:

-1

result:

ok correct

Test #52:

score: 0
Accepted
time: 0ms
memory: 7784kb

input:

19 40
???????????????????

output:

NAACCCCCACCCCCCCCCC

result:

ok correct

Test #53:

score: 0
Accepted
time: 0ms
memory: 8240kb

input:

20 1019
????????????????????

output:

-1

result:

ok correct

Test #54:

score: 0
Accepted
time: 2ms
memory: 9372kb

input:

21 1218
?????????????????????

output:

-1

result:

ok correct

Test #55:

score: 0
Accepted
time: 2ms
memory: 10348kb

input:

22 1348
??????????????????????

output:

-1

result:

ok correct

Test #56:

score: 0
Accepted
time: 3ms
memory: 11288kb

input:

23 476
???????????????????????

output:

-1

result:

ok correct

Test #57:

score: 0
Accepted
time: 0ms
memory: 12524kb

input:

24 1445
????????????????????????

output:

-1

result:

ok correct

Test #58:

score: 0
Accepted
time: 3ms
memory: 13844kb

input:

25 1331
?????????????????????????

output:

-1

result:

ok correct

Test #59:

score: 0
Accepted
time: 6ms
memory: 15360kb

input:

26 459
??????????????????????????

output:

NNNANAAAAAAAAAAAACCCCCCCCC

result:

ok correct

Test #60:

score: 0
Accepted
time: 8ms
memory: 18932kb

input:

27 398
???????????????????????????

output:

NNANAAAAAAAAACCCCCCACCCCCCC

result:

ok correct

Test #61:

score: 0
Accepted
time: 4ms
memory: 19060kb

input:

28 274
????????????????????????????

output:

NNAAAAAAACCCCCCCACCCCCCCCCCC

result:

ok correct

Test #62:

score: 0
Accepted
time: 7ms
memory: 21216kb

input:

29 1624
?????????????????????????????

output:

-1

result:

ok correct

Test #63:

score: 0
Accepted
time: 7ms
memory: 23236kb

input:

30 2079
??????????????????????????????

output:

-1

result:

ok correct

Test #64:

score: 0
Accepted
time: 3ms
memory: 26076kb

input:

31 2067
???????????????????????????????

output:

-1

result:

ok correct

Test #65:

score: 0
Accepted
time: 8ms
memory: 28832kb

input:

32 1267
????????????????????????????????

output:

-1

result:

ok correct

Test #66:

score: 0
Accepted
time: 12ms
memory: 31728kb

input:

33 928
?????????????????????????????????

output:

NNNNAANAAAAAAAAAACCCCCCCCCCCCCCCC

result:

ok correct

Test #67:

score: 0
Accepted
time: 12ms
memory: 34948kb

input:

34 298
??????????????????????????????????

output:

NNAAAAACCCCCCCACCCCCCCCCCCCCCCCCCC

result:

ok correct

Test #68:

score: 0
Accepted
time: 12ms
memory: 38468kb

input:

35 2361
???????????????????????????????????

output:

-1

result:

ok correct

Test #69:

score: 0
Accepted
time: 33ms
memory: 42684kb

input:

36 489
????????????????????????????????????

output:

NANAAAAAAAAAAACCCCCCCCCCCCCCCCCCACCC

result:

ok correct

Test #70:

score: 0
Accepted
time: 20ms
memory: 46768kb

input:

37 294
?????????????????????????????????????

output:

NAAAAAAAAAAAACCCCCACCCCCCCCCCCCCCCCCC

result:

ok correct

Test #71:

score: 0
Accepted
time: 24ms
memory: 51332kb

input:

38 1558
??????????????????????????????????????

output:

NNNNNNAANAAAAAAAAAACCCCCCCCCCCCCCCCCCC

result:

ok correct

Test #72:

score: 0
Accepted
time: 15ms
memory: 56332kb

input:

39 1319
???????????????????????????????????????

output:

NNNNANAAAAAAAAAAACCCCCACCCCCCCCCCCCCCCC

result:

ok correct

Test #73:

score: 0
Accepted
time: 27ms
memory: 61368kb

input:

40 993
????????????????????????????????????????

output:

NNNAAAAAAAAAAAAAAACCCCCACCCCCCCCCCCCCCCC

result:

ok correct

Test #74:

score: 0
Accepted
time: 22ms
memory: 59524kb

input:

40 498
ACNANACNNACNACNNNCNCNNNANNNACNCCACAA?ANA

output:

-1

result:

ok correct

Test #75:

score: 0
Accepted
time: 12ms
memory: 59692kb

input:

40 855
NAAANAACNNNCNAANCNANCNANACANCCAANCACNCAC

output:

-1

result:

ok correct

Test #76:

score: 0
Accepted
time: 4ms
memory: 59828kb

input:

40 1007
?CNACNNAANACANACNACCC?CAANNCCCCANNANCACN

output:

-1

result:

ok correct

Test #77:

score: 0
Accepted
time: 11ms
memory: 60468kb

input:

40 1778
NACANANN?CCANNCCAACNNCCNCCCNCCNACCNC?NNN

output:

-1

result:

ok correct

Test #78:

score: 0
Accepted
time: 7ms
memory: 60040kb

input:

40 2186
ACCCACAN?NNA?AACCNNNN?ANACCANCNCNNCA?NCN

output:

-1

result:

ok correct

Test #79:

score: 0
Accepted
time: 0ms
memory: 60048kb

input:

40 332
ACAC?NCCCANAA?ACCNNC?NAC?CAC?CNCNNACNNNN

output:

-1

result:

ok correct

Test #80:

score: 0
Accepted
time: 19ms
memory: 59676kb

input:

40 712
ANCNANAAC?CACAACA?CNACCCANAACCA?CNNAANCN

output:

-1

result:

ok correct

Test #81:

score: 0
Accepted
time: 11ms
memory: 59888kb

input:

40 1127
C?CAAAANNCANANAC?NCANACANAACAACANNCCNCAC

output:

-1

result:

ok correct

Test #82:

score: 0
Accepted
time: 19ms
memory: 60268kb

input:

40 1835
CANNCAANNNAANANNCACANAC?CCCCAACA?NNNCAC?

output:

-1

result:

ok correct

Test #83:

score: 0
Accepted
time: 11ms
memory: 59728kb

input:

40 2009
CANAAAN?ANAACNCCNCCNCAAANCANCCAN?CCNCAAN

output:

-1

result:

ok correct

Test #84:

score: 0
Accepted
time: 16ms
memory: 60372kb

input:

40 54
CNAC?ACAAC?ACC?ANC?C?NNCAANCCAC?NCN?CACA

output:

-1

result:

ok correct

Test #85:

score: 0
Accepted
time: 12ms
memory: 59572kb

input:

40 955
?A?ANA?NN?C?ANC??CNNACAAC?N?AAN?AN??ANNA

output:

-1

result:

ok correct

Test #86:

score: 0
Accepted
time: 8ms
memory: 60188kb

input:

40 1451
??CCCA?N?ACCN?C???NNN??C?ANAN??NCNA??NAN

output:

-1

result:

ok correct

Test #87:

score: 0
Accepted
time: 12ms
memory: 60364kb

input:

40 1526
CN??AC?CCCCNACCNCNCCNC?CAAN?C?CA??ANCN?A

output:

-1

result:

ok correct

Test #88:

score: 0
Accepted
time: 3ms
memory: 60124kb

input:

40 2453
C?NC?CCAAN?ACCCNCC??ACAANCANCNCNNAACC?NN

output:

-1

result:

ok correct

Test #89:

score: 0
Accepted
time: 0ms
memory: 59988kb

input:

40 166
?NC??AACAN??NCA?CCAA?A??CNNN?ACNN?AN?ANC

output:

ANCCCAACANBCNCACCCAABACCCNNNCACNNCANBANC

result:

ok correct

Test #90:

score: 0
Accepted
time: 11ms
memory: 60596kb

input:

40 887
?NA?AN?N?A?ANN??N?ANCAN?N????AC?NN?NA???

output:

NNANANANAAAANNCANAANCANCNCACCACCNNCNACCC

result:

ok correct

Test #91:

score: 0
Accepted
time: 17ms
memory: 60780kb

input:

40 1310
CCN?NNANC??CANN??NC?N??NA?NNNNCN?N?CCCCC

output:

-1

result:

ok correct

Test #92:

score: 0
Accepted
time: 11ms
memory: 60204kb

input:

40 1568
ANCN?N?NACC??NNN?AAC?AANA?CA?NC?CNNAN??N

output:

-1

result:

ok correct

Test #93:

score: 0
Accepted
time: 20ms
memory: 60236kb

input:

40 2035
CA?N?ACCNN??CANA?NC?NACNC??CC???NCA?N?AC

output:

-1

result:

ok correct

Test #94:

score: 0
Accepted
time: 20ms
memory: 60880kb

input:

40 126
AC?CACCCN???C?NCCN?NN??CN?CNCN?C?N?C?A?C

output:

ACACACCCNACACANCCNBNNCACNCCNCNCCCNCCCACC

result:

ok correct

Test #95:

score: 0
Accepted
time: 15ms
memory: 60460kb

input:

40 962
CCC???A??????AN?N???C?NN??CANA?CNA??N???

output:

CCCNNNANNANANANANAAACCNNAACANACCNACCNCCC

result:

ok correct

Test #96:

score: 0
Accepted
time: 4ms
memory: 60056kb

input:

40 1043
?A??NANA?CN?N?AN?ANN?CNAANCC??AAANNN????

output:

-1

result:

ok correct

Test #97:

score: 0
Accepted
time: 21ms
memory: 60556kb

input:

40 1638
N?ANA?NA???A??N?CNNAA???NC????CNN??AC??N

output:

-1

result:

ok correct

Test #98:

score: 0
Accepted
time: 15ms
memory: 60692kb

input:

40 2240
NNC??NCA???N?N?NNC??CNNNAN??C?AN??AC?C??

output:

-1

result:

ok correct

Test #99:

score: 0
Accepted
time: 23ms
memory: 60692kb

input:

40 55
N?NCNC????C?A??A?A?NN??ACC??C??NC???ACN?

output:

-1

result:

ok correct

Test #100:

score: 0
Accepted
time: 19ms
memory: 60748kb

input:

40 639
C???NN??C?N?N????N?CA?NCAN????AN????NA??

output:

CAANNNAACANANAACCNACACNCANCCCCANCCCCNACC

result:

ok correct

Test #101:

score: 0
Accepted
time: 0ms
memory: 60268kb

input:

40 1438
?C?A?NA?AN???CA???NAAAN??A?NNANNCAA?????

output:

-1

result:

ok correct

Test #102:

score: 0
Accepted
time: 11ms
memory: 60368kb

input:

40 1660
???C?A???????NN??AANNAC???A?CN??ACN?AC?C

output:

-1

result:

ok correct

Test #103:

score: 0
Accepted
time: 15ms
memory: 61020kb

input:

40 2016
??AA??N?N??A?C?C????????C????C?C?CN??N?A

output:

-1

result:

ok correct

Test #104:

score: 0
Accepted
time: 11ms
memory: 60252kb

input:

40 242
?C???A???AA??A??C?CN???C???A?ANA?NN??AA?

output:

NCAAAAAAAAAACAACCCCNCCCCCCCACANACNNCCAAC

result:

ok correct

Test #105:

score: 0
Accepted
time: 30ms
memory: 60804kb

input:

40 711
??A?AA?C??C???CCNA?????C????A?????A??C??

output:

NNANAAACAACACACCNACCCCCCCCACACCCCCACCCCC

result:

ok correct

Test #106:

score: 0
Accepted
time: 11ms
memory: 61164kb

input:

40 1094
??AACN??N?A?????C????AA??CC???CC?N?A????

output:

NNAACNANNAAAAAAACACCAAACCCCCCCCCCNCACCCC

result:

ok correct

Test #107:

score: 0
Accepted
time: 14ms
memory: 60508kb

input:

40 1878
?A??AACCA????N???A???C?C?C??C?NANC?N?NAC

output:

-1

result:

ok correct

Test #108:

score: 0
Accepted
time: 16ms
memory: 61304kb

input:

40 2082
AC??ACANC?CN?C?N???C?N???N??C?CC?????C?C

output:

-1

result:

ok correct

Test #109:

score: 0
Accepted
time: 3ms
memory: 60636kb

input:

40 268
N?N??NNNCNC??CAC????A?C?????N???AN??NC??

output:

NANBBNNNCNCBBCACCCCCACCCCCCCNCCCANCCNCCC

result:

ok correct

Test #110:

score: 0
Accepted
time: 16ms
memory: 60656kb

input:

40 960
?????????N???NA?????????C??AC???AN?A???A

output:

NNAANAAAANAAANAAAAAAACCCCCCACCCCANCACCCA

result:

ok correct

Test #111:

score: 0
Accepted
time: 12ms
memory: 60856kb

input:

40 1342
???C?????C?????NA?N??N?C?????A?N???NA???

output:

NNNCNNNNNCNAAANNAANAANACAACCCACNCCCNACCC

result:

ok correct

Test #112:

score: 0
Accepted
time: 21ms
memory: 60644kb

input:

40 1739
?A?A???A???N?A??N???C???NCC??C??ANN???A?

output:

-1

result:

ok correct

Test #113:

score: 0
Accepted
time: 27ms
memory: 61040kb

input:

40 2484
??????N????N?????N?C??N????????????A???N

output:

-1

result:

ok correct

Test #114:

score: 0
Accepted
time: 32ms
memory: 61484kb

input:

40 116
?CN????????A??A???C????????????????C????

output:

ACNACCACCCCACCACCCCCCCCCCCCCCCCCCCCCCCCC

result:

ok correct

Test #115:

score: 0
Accepted
time: 15ms
memory: 61224kb

input:

40 538
NC???N?????????????NN??N????????CC???N??

output:

NCAAANAAAAAAAACCCCCNNAANCACCCCCCCCCCCNCC

result:

ok correct

Test #116:

score: 0
Accepted
time: 23ms
memory: 61176kb

input:

40 1128
?????AN?????CN????N?A????C???C??????????

output:

NNNAAANAAAAACNACACNAAACCCCCCCCCCCCCCCCCC

result:

ok correct

Test #117:

score: 0
Accepted
time: 23ms
memory: 61316kb

input:

40 1819
?????????C?AC?????C??A??NC?????????????C

output:

-1

result:

ok correct

Test #118:

score: 0
Accepted
time: 11ms
memory: 61188kb

input:

40 2198
??????A???N????????ANN???N?C??????C?????

output:

-1

result:

ok correct

Test #119:

score: 0
Accepted
time: 15ms
memory: 61432kb

input:

40 373
???????????C?A?????????A???A?C??????????

output:

NACANAACACCCAACCCCCCCCCACCCACCCCCCCCCCCC

result:

ok correct

Test #120:

score: 0
Accepted
time: 26ms
memory: 61140kb

input:

40 744
?????????????????C????????????A????C???N

output:

NNNAAAAAAAAACCCCCCCCCCACCCCCCCACCCCCCCCN

result:

ok correct

Test #121:

score: 0
Accepted
time: 29ms
memory: 61352kb

input:

40 1103
???????????????????????????N????????????

output:

NNNNAAAAAAAAAAACCACCCCCCCCCNACCCCCCCCCCC

result:

ok correct

Test #122:

score: 0
Accepted
time: 27ms
memory: 61440kb

input:

40 1866
???????A??????A??A???????????????C??????

output:

NNNNNNNAANAAAAAAAAAACCCCCCCCCACCCCCCCCCC

result:

ok correct

Test #123:

score: 0
Accepted
time: 12ms
memory: 61172kb

input:

40 2466
????????????CN?????????????????N??CA????

output:

-1

result:

ok correct

Test #124:

score: 0
Accepted
time: 31ms
memory: 61200kb

input:

40 1
?????????????????????????????????????NAC

output:

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANAC

result:

ok correct