Submission #14500420


Source Code Expand

/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <assert.h>
#include <math.h>
#include <memory.h>
#include <stdio.h>

#include <algorithm>
#include <complex>
#include <ctime>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define left asdgashgrketwjklrej
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-12
#define M_PI 3.141592653589793
#define bsize 1024

#define ldouble long double
using namespace std;

#define bs 998244353

const int N = 500031;

string st;
int k;
vector<int> v;
int cnt;
int dp[3][331][331];
int sdp_take[661][661],sdp_drop[661][661];

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", sttextdout);
  ios_base::sync_with_stdio(0);
  // cin.tie(0);

  cin>>st>>k;
  st=st+"0";
  for (int i=0;i<st.size();i++){
	  if (st[i]=='0'){
		  v.push_back(cnt);
		  cnt=0;
	  }
	  else
	  {
		  ++cnt;
	  }
  }

  reverse(v.begin(),v.end());

  dp[0][0][0]=1;

  for (int i=0;i<v.size();i++){

	  for (int j=0;j<=300;j++){
		  for (int q=0;q<=300;q++){
			  dp[1-i%2][j][q]=0;
		  }
	  }

	  for (int j=0;j<=300;j++){
		  for (int q=0;q<=300;q++){
			  sdp_take[j][q]=0;
		  }
	  }

	  for (int j=0;j<=600;j++){
		  for(int q=0;q<=600;q++)
		  {
			  sdp_drop[j][q]=0;
		  }
	  }

	  for (int j=0;j<=300;j++){
		  for (int q=0;q<=300;q++){
			  sdp_drop[j+q][j]=dp[i%2][j][q];
		  }
	  }

	  for (int j=0;j<=600;j++){
		  for (int q=0;q<=600;q++){
			  if (q)
				  sdp_drop[j][q]+=sdp_drop[j][q-1];
			  sdp_drop[j][q]%=bs;
		  }
	  }

	  for (int j=0;j<=300;j++){
		  for (int q=0;q<=300;q++){
			  sdp_take[j][q]=dp[i%2][j][q];
			  if (j)
				  sdp_take[j][q]+=sdp_take[j-1][q];
			  sdp_take[j][q]%=bs;
		  }
	  }

	  for (int new_in_hand=0;new_in_hand<=300;new_in_hand++){
		  for (int new_dif=0;new_dif<=300;new_dif++){
			  // dropped some here, definitely more than 0, at most min(300-new_in_hand,new_dif);
			  int BOUND=min(300-new_in_hand,new_dif);
			  //for (int how_much=1;how_much+new_in_hand<=300&&how_much<=new_dif;how_much++){
				  dp[1-i%2][new_in_hand][new_dif]+=sdp_drop[new_in_hand+new_dif][new_in_hand+BOUND];
				  dp[1-i%2][new_in_hand][new_dif]%=bs;
				  //if (new_in_hand>0)
					  dp[1-i%2][new_in_hand][new_dif]-=sdp_drop[new_in_hand+new_dif][new_in_hand];
				  if (dp[1-i%2][new_in_hand][new_dif]<0)
					  dp[1-i%2][new_in_hand][new_dif]+=bs;

				  //dp[1-i%2][new_in_hand][new_dif]+=dp[i%2][new_in_hand+how_much][new_dif-how_much];
				  //dp[1-i%2][new_in_hand][new_dif]%=bs;
			  //}
			  // took some here, possibly 0, at most min(v[i],new_in_hand)
			  int ways=sdp_take[new_in_hand][new_dif];
			  if (v[i]<new_in_hand)
				  ways-=sdp_take[new_in_hand-v[i]-1][new_dif];
			  if (ways<0)
				  ways+=bs;
			  dp[1-i%2][new_in_hand][new_dif]+=ways;
			  dp[1-i%2][new_in_hand][new_dif]%=bs;
		  }
	  }
	/* for (int in_hand=0;in_hand<=300;in_hand++){
		 for (int total_dif=0;total_dif<=300;total_dif++){
			 if (dp[i%2][in_hand][total_dif]==0)
				 continue;
			 // drop some here
			 for (int to_drop=1;to_drop<=in_hand;to_drop++){
				 dp[1-i%2][in_hand-to_drop][total_dif+to_drop]+=dp[i%2][in_hand][total_dif];
				 dp[1-i%2][in_hand-to_drop][total_dif+to_drop]%=bs;
			 }
			 // take some, possibly 0
			 for (int to_take=0;to_take<=v[i];to_take++){
				 dp[1-i%2][in_hand+to_take][total_dif]+=dp[i%2][in_hand][total_dif];
				 dp[1-i%2][in_hand+to_take][total_dif]%=bs;
			 }
		 }
	 }*/

  }

  int ans=0;

  for (int i=0;i<=k&&i<=300;i++){
	  ans+=dp[v.size()%2][0][i];
	  ans%=bs;
  }

  cout<<ans<<endl;

  cin.get(); cin.get();
  return 0;
}

Submission Info

Submission Time
Task C - Shift
User LeBron
Language C++ (GCC 9.2.1)
Score 800
Code Size 4131 Byte
Status AC
Exec Time 715 ms
Memory 6772 KiB

Compile Error

./Main.cpp:39: warning: "M_PI" redefined
   39 | #define M_PI 3.141592653589793
      | 
In file included from /usr/include/c++/9/cmath:45,
                 from /usr/include/c++/9/math.h:36,
                 from ./Main.cpp:7:
/usr/include/math.h:777: note: this is the location of the previous definition
  777 | # define M_PI  3.14159265358979323846 /* pi */
      | 
./Main.cpp: In function ‘int main()’:
./Main.cpp:64:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   64 |   for (int i=0;i<st.size();i++){
      |                ~^~~~~~~~~~
./Main.cpp:79:17: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   79 |   for (int i=0;i<v.size();i++){
      |                ~^~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 39
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 377 ms 6736 KiB
02.txt AC 331 ms 6624 KiB
03.txt AC 361 ms 6684 KiB
04.txt AC 351 ms 6580 KiB
05.txt AC 360 ms 6624 KiB
06.txt AC 409 ms 6636 KiB
07.txt AC 388 ms 6768 KiB
08.txt AC 384 ms 6728 KiB
09.txt AC 715 ms 6704 KiB
10.txt AC 13 ms 6344 KiB
11.txt AC 374 ms 6732 KiB
12.txt AC 376 ms 6624 KiB
13.txt AC 373 ms 6720 KiB
14.txt AC 334 ms 6632 KiB
15.txt AC 200 ms 6704 KiB
16.txt AC 216 ms 6688 KiB
17.txt AC 714 ms 6692 KiB
18.txt AC 375 ms 6736 KiB
19.txt AC 42 ms 6720 KiB
20.txt AC 43 ms 6572 KiB
21.txt AC 31 ms 6616 KiB
22.txt AC 53 ms 6624 KiB
23.txt AC 652 ms 6636 KiB
24.txt AC 663 ms 6616 KiB
25.txt AC 19 ms 6692 KiB
26.txt AC 22 ms 6732 KiB
27.txt AC 372 ms 6764 KiB
28.txt AC 375 ms 6624 KiB
29.txt AC 11 ms 6280 KiB
30.txt AC 14 ms 6236 KiB
31.txt AC 15 ms 6700 KiB
32.txt AC 14 ms 6612 KiB
33.txt AC 53 ms 6724 KiB
34.txt AC 34 ms 6696 KiB
35.txt AC 40 ms 6692 KiB
36.txt AC 14 ms 6668 KiB
s1.txt AC 24 ms 6772 KiB
s2.txt AC 25 ms 6728 KiB
s3.txt AC 85 ms 6688 KiB