Submission #44666006


Source Code Expand

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define MOD 1000000007
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
	int res = 1;
	while(k)
	{
		if(k & 1) Mul(res, x);
		Sqr(x), k >>= 1;
	}
	return res;
}
const int N = 3e3 + 5;
int n, m;
char ch[N];
struct Segment
{
	int l, r;
	void read()
	{
		scanf("%d %d", &l, &r);
	}
	friend bool operator < (const Segment &A, const Segment &B)
	{
		if(A.l != B.l) return A.l < B.l;
		return A.r < B.r;
	}
}seg[N];
int a[N], c1[N], c2[N];
// c1 : 尽可能把 1 向右移
// c2 : 尽可能把 1 向左移
int lj[N], rj[N];
int f[N][N];
int main()
{
	scanf("%d %d", &n, &m);
	scanf("%s", ch + 1);
	for(int i = 1; i <= n; ++i)
		a[i] = ch[i] - '0';
	for(int i = 1; i <= m; ++i)
		seg[i].read();
	int cnt = 0, rmx = 0;
	for(int i = 1; i <= m; ++i)
	{
		if(seg[i].r > rmx) seg[++cnt] = seg[i];
		chkmx(rmx, seg[i].r);
	}
	m = cnt;
	for(int i = 1; i <= m; ++i)
	{
		int l = seg[i].l, r = seg[i].r;
		int num1 = 0, num2 = 0;
		for(int j = l; j <= r; ++j)
		{
			num1 += a[j] | c1[j];
			num2 += a[j] | c2[j];
			a[j] = c1[j] = c2[j] = 0;
		}
		for(int j = r; j > r - num1; --j)
			c1[j] = 1;
		for(int j = l; j < l + num2; ++j)
			c2[j] = 1;
	}
	for(int i = 1; i <= n; ++i)
	{
		lj[i] = lj[i - 1] + c1[i];
		rj[i] = rj[i - 1] + c2[i];
	}
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i)
	{
		for(int j = lj[i]; j <= rj[i]; ++j)
		{
			Inc(f[i][j], f[i - 1][j]);
			if(j) Inc(f[i][j], f[i - 1][j - 1]);
		}
	}
	printf("%d\n", f[n][lj[n]]);
	return 0;
}

Submission Info

Submission Time
Task F - Shuffling
User Schucking_Sattin
Language C++ (GCC 9.2.1)
Score 900
Code Size 2582 Byte
Status AC
Exec Time 20 ms
Memory 16048 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:61:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   61 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
./Main.cpp:62:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   62 |  scanf("%s", ch + 1);
      |  ~~~~~^~~~~~~~~~~~~~
./Main.cpp: In member function ‘void Segment::read()’:
./Main.cpp:46:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   46 |   scanf("%d %d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 27
Set Name Test Cases
Sample subtask0_0.txt, subtask0_1.txt, subtask0_2.txt
All subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_2.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt
Case Name Status Exec Time Memory
subtask0_0.txt AC 6 ms 3724 KiB
subtask0_1.txt AC 3 ms 3740 KiB
subtask0_2.txt AC 2 ms 3844 KiB
subtask1_0.txt AC 16 ms 15780 KiB
subtask1_1.txt AC 14 ms 15900 KiB
subtask1_10.txt AC 14 ms 15880 KiB
subtask1_11.txt AC 14 ms 15824 KiB
subtask1_12.txt AC 15 ms 15892 KiB
subtask1_13.txt AC 14 ms 15904 KiB
subtask1_14.txt AC 15 ms 16004 KiB
subtask1_15.txt AC 19 ms 15740 KiB
subtask1_16.txt AC 14 ms 15764 KiB
subtask1_17.txt AC 20 ms 16048 KiB
subtask1_18.txt AC 16 ms 15816 KiB
subtask1_19.txt AC 14 ms 15884 KiB
subtask1_2.txt AC 14 ms 15832 KiB
subtask1_20.txt AC 15 ms 15876 KiB
subtask1_21.txt AC 14 ms 15736 KiB
subtask1_22.txt AC 15 ms 15928 KiB
subtask1_23.txt AC 17 ms 15896 KiB
subtask1_3.txt AC 15 ms 15772 KiB
subtask1_4.txt AC 17 ms 15988 KiB
subtask1_5.txt AC 16 ms 15952 KiB
subtask1_6.txt AC 15 ms 15776 KiB
subtask1_7.txt AC 16 ms 15764 KiB
subtask1_8.txt AC 18 ms 15968 KiB
subtask1_9.txt AC 16 ms 15820 KiB