提出 #59862524


ソースコード 拡げる

#include<bits/stdc++.h>
#define ll long long
//#define int long long
#define ci const int
#define rg int
#define ld long double
#define ls (x<<1)
#define rs (x<<1)|1
#define mid ((l+r)>>1)
#define fo(i,l,r) for(ll i=(l);i<=(r);++i)
#define fd(i,l,r) for(ll i=(l);i>=(r);--i)
#define fu(i,l,r) for(ll i=(l);i<(r);++i)
#define gcd __gcd
#define P(x) __builtin_popcountll(x)
#define W(x) __builtin_ctzll(x)
#define lowbit(x) (x&-x)
#define mp make_pair
using namespace std;
bool ST;
ci N=2e6+5,M=505,mod=998244353;
const ll base=71;
const ll inf=1e18;
void _(ll &a,ll b){a=(a+b)%mod;}
inline ll read(){ll u,f=1;char o;while((o=getchar())<48||o>57)if(o==45)f=-1;u=(o^48);while((o=getchar())>=48&&o<=57)u=(u<<1)+(u<<3)+(o^48);return u*f;}
void write(ll x){if(x<0)putchar(45),x=-x;if(x>9)write(x/10);putchar(x%10+48);};
ll n,q,a[N],t[N];
char ch[N];
bool ED;int main()
{cerr<<(&ST-&ED)/1048576.0<<" MB\n";
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
//	freopen("easygame.in","r",stdin);
//	freopen("easygame.out","w",stdout);
	int T=1;
	while(T--)
	{
		n=read();ll k=read();
		scanf("%s",ch+1);
//		n=strlen(ch+1);
		ch[n+1]='0';
		++n;
		ll s=0;bool F=0;
		fo(i,1,n)
		{
			if(ch[i]=='1')F=1;
			else if(F)
			{
				++s;
				if(s==k)
				{
					int to=i-1;
					while(ch[to]=='1')--to;
					ll now=to+1;
					ll len=0;
					while(ch[to]=='0')--to,++len;
					fo(j,now,i-1)ch[j-len]='1';
					fo(j,i-len,i-1)ch[j]='0';
				}
				F=0;
			}
		}
		fo(i,1,n-1)cout<<ch[i];
	}
	return 0;
}

提出情報

提出日時
問題 C - Move Segment
ユーザ Butanlishi
言語 C++ 20 (gcc 12.2)
得点 300
コード長 1560 Byte
結果 AC
実行時間 8 ms
メモリ 4444 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                 scanf("%s",ch+1);
      |                 ~~~~~^~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 2
AC × 28
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3764 KiB
random_01.txt AC 7 ms 4320 KiB
random_02.txt AC 7 ms 4252 KiB
random_03.txt AC 7 ms 4252 KiB
random_04.txt AC 7 ms 4320 KiB
random_05.txt AC 7 ms 4092 KiB
random_06.txt AC 8 ms 4444 KiB
random_07.txt AC 1 ms 3808 KiB
random_08.txt AC 7 ms 4316 KiB
random_09.txt AC 3 ms 3892 KiB
random_10.txt AC 7 ms 4220 KiB
random_11.txt AC 7 ms 4424 KiB
random_12.txt AC 7 ms 4124 KiB
random_13.txt AC 1 ms 3684 KiB
random_14.txt AC 7 ms 4208 KiB
random_15.txt AC 2 ms 3716 KiB
random_16.txt AC 7 ms 4248 KiB
random_17.txt AC 7 ms 4316 KiB
random_18.txt AC 7 ms 4216 KiB
random_19.txt AC 6 ms 4156 KiB
random_20.txt AC 7 ms 4320 KiB
random_21.txt AC 3 ms 3884 KiB
random_22.txt AC 8 ms 4252 KiB
random_23.txt AC 3 ms 3972 KiB
random_24.txt AC 7 ms 4252 KiB
random_25.txt AC 6 ms 4196 KiB
sample_01.txt AC 1 ms 3784 KiB
sample_02.txt AC 1 ms 3668 KiB