98172024-03-08 03:11:52SleepyOverlordSzitakötő (50 pont)cpp17Időlimit túllépés 34/50600ms8380 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define MX(x, y) x = max(x, y);
#define MN(x, y) x = min(x, y);

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

template <class T> ostream& operator <<(ostream & os, const vector<T> &vec)
{
	for (int i = 0; i < vec.size() - 1; ++i) os << vec[i] << ' ';
	return os << vec[vec.size() - 1];
}

template <class T1, class T2> ostream& operator <<(ostream & os, const pair<T1, T2> &p)
{
	return os << p.X << " " << p.Y;
}

template <typename T>
void pr(T var1)
{
	cout << var1 << '\n';
}
template <typename T, typename... Types>
void pr(T var1, Types... var2)
{
	cout << var1;
	pr(var2...);
}

void in(int &n, VI &a) //array of ints
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VS &a) //array of strings
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VPII &a) //array of pairs
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i].X >> a[i].Y;
}

void in(int &n, int &m, VVI &g) //unweighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, VVI &g) //unweighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, int &m, vector <VPII> &g) //weighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

void in(int &n, vector <VPII> &g) //weighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

const int MOD = 1e9 + 7;

int n, k;
VI a, pow2;
vector <ULL> ps;

int main()
{
	#ifdef AT_HOME
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	cin >> n >> k;
	if (n == 1)
	{
		pr(2);
		return 0;
	}
	a.RS(n + 1);
	ps.RS(n + 1);
	pow2.RS(n + 1);
	FOR(i, 1, n) 
	{
		cin >> a[i];
		ps[i] = ps[i - 1] + a[i];
	}

	pow2[0] = 1;
	FOR(i, 1, n) pow2[i] = pow2[i - 1] * 2 % MOD;

	ULL solLeft = 0, solRight = 0;
	ULL larvaSize = a[k];
	//Bimbo balra kell induljon, hogy tulelje (kiveve ha utolso)
	FORD(i, k - 1, 2)
	{
		//Ha i balra indult
		if (larvaSize >= ps[i]) solLeft = (solLeft + pow2[i - 1]) % MOD;
		//Ha i jobbra indult
		larvaSize += a[i];
	}
	//Az elso mindegy merre indult
	if (k > 1) larvaSize += a[1], solLeft += 2;
	VI dp(n + 1); //hany lehetoseg van ha i-1-el bezarolag jobbra indulunk
	dp[n] = 2;
	//Bimbo ezutan talalkozik a "jobboldallal"
	FORD(i, n - 1, k + 1)
	{
		larvaSize = ps[i - 1];
		//Ha i jobbra indult
		if (larvaSize > ps[n] - ps[i - 1]) //Meg tudunk enni mindenkit aki maradt
		{
			dp[i] = (dp[i + 1] + pow2[n - i]) % MOD;
		}
		else
		{
			LL s = a[i];
			int j = i; //[i, j] intervallumban mindenki jobbra megy
			dp[i] = dp[i + 1];
			while (j < n and larvaSize > s + a[j + 1])
			{
				//if (s <= a[j + 1]) 
				dp[i] = (dp[i] + dp[j + 2]) % MOD; //j + 1. balra jon szembe
				s += a[j++ + 1];
			}
		}
		//Ha i tul nagy
		if (larvaSize <= a[i])
		{
			pr(0);
			return 0;
		}
	}
	solRight = dp[k + 1];
	if (k < n)
		if (ps[n - 1] <= a[n])
		{
			pr(0);
			return 0;
		}
		else ;
	else solRight = 2; //ha utolso, indulhatott jobbra is es minden ugyanaz

	pr(solLeft % MOD * solRight % MOD);

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base34/50
1Elfogadva0/03ms1876 KiB
2Időlimit túllépés0/0551ms3468 KiB
3Elfogadva1/13ms2572 KiB
4Elfogadva1/13ms2584 KiB
5Elfogadva1/13ms2680 KiB
6Elfogadva1/13ms2892 KiB
7Elfogadva1/13ms3024 KiB
8Elfogadva1/13ms2976 KiB
9Elfogadva1/13ms3040 KiB
10Elfogadva2/23ms3040 KiB
11Elfogadva2/23ms3116 KiB
12Elfogadva2/23ms3248 KiB
13Elfogadva2/23ms3476 KiB
14Elfogadva2/23ms3544 KiB
15Elfogadva2/24ms3544 KiB
16Elfogadva2/23ms3544 KiB
17Elfogadva2/23ms3540 KiB
18Elfogadva2/23ms3784 KiB
19Elfogadva2/24ms3772 KiB
20Elfogadva2/23ms3764 KiB
21Elfogadva1/13ms3988 KiB
22Időlimit túllépés0/2600ms5208 KiB
23Időlimit túllépés0/2550ms5176 KiB
24Időlimit túllépés0/2558ms5164 KiB
25Időlimit túllépés0/2558ms5180 KiB
26Elfogadva2/248ms8172 KiB
27Időlimit túllépés0/2568ms5344 KiB
28Időlimit túllépés0/2558ms5636 KiB
29Időlimit túllépés0/2563ms5572 KiB
30Időlimit túllépés0/2569ms5572 KiB
31Elfogadva2/246ms8380 KiB