Submission #654173

# Submission time Handle Problem Language Result Execution time Memory
654173 2022-10-30T09:04:29 Z kym Homework (CEOI22_homework) C++14
100 / 100
506 ms 395952 KB
#include <bits/stdc++.h>
using namespace std;
#define int ll 
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#else
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first 	
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
typedef tuple<ll,ll,ll,ll> ti4;
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> bool chmax(T& a, const T b) { return a<b ? a = b, 1 : 0; }
template <typename T> bool chmin(T& a, const T b) { return a>b ? a = b, 1 : 0; }
const int MAXN = 10000005;
int sum[MAXN];
vector<int> V[MAXN];
string str; 
int dpdpmin(int st, int en) {
	if(st==en && str[st]=='?')return 1;
	
	auto it=upper_bound(all(V[sum[st]-1]),st);
	if(str[st]=='m' && str[st+1]=='a' && str[st+2] == 'x') {
		return dpdpmin(st+4,*it-1) + dpdpmin(*it+1,en-1);
	} else {
		return min(dpdpmin(st+4,*it-1) , dpdpmin(*it+1,en-1));
	}
}

int dpdpmax(int st, int en) {
	if(st==en && str[st]=='?')return 1;
	
	auto it=upper_bound(all(V[sum[st]-1]),st);
	if(str[st]=='m' && str[st+1]=='i' && str[st+2] == 'n') {
		return dpdpmax(st+4,*it-1) + dpdpmax(*it+1,en-1);
	} else {
		return min(dpdpmax(st+4,*it-1) , dpdpmax(*it+1,en-1));
	}
}
int32_t main() 
{
	IAMSPEED
	cin >> str;
	int n=0;
	FOR(i,0,str.size()-1) {
		if(str[i]=='?')++n;
		if(i)sum[i]=sum[i-1];
		if(str[i]=='m'){
			sum[i]+=1;
			V[sum[i]].pb(i);
			db(i);
		}
		if(str[i]==','){
			sum[i]+=-1;
			V[sum[i]].pb(i);
			db(i);
		}
		
	}
	dba(sum,0,str.size()-1);
	int mn=dpdpmin(0,str.size()-1);
	int mx=dpdpmax(0,str.size()-1);
	int mnpossible=mx;
	int mxpossible=n-mn+1;
	cout << mxpossible-mnpossible+1;
}


# Verdict Execution time Memory Grader output
1 Correct 104 ms 235080 KB Output is correct
2 Correct 109 ms 235024 KB Output is correct
3 Correct 106 ms 235056 KB Output is correct
4 Correct 106 ms 235084 KB Output is correct
5 Correct 112 ms 235160 KB Output is correct
6 Correct 107 ms 235064 KB Output is correct
7 Correct 109 ms 235108 KB Output is correct
8 Correct 121 ms 235148 KB Output is correct
9 Correct 110 ms 235248 KB Output is correct
10 Correct 118 ms 235044 KB Output is correct
11 Correct 112 ms 235140 KB Output is correct
12 Correct 113 ms 235132 KB Output is correct
13 Correct 113 ms 235100 KB Output is correct
14 Correct 112 ms 235132 KB Output is correct
15 Correct 115 ms 235072 KB Output is correct
16 Correct 117 ms 235148 KB Output is correct
17 Correct 114 ms 235144 KB Output is correct
18 Correct 119 ms 235088 KB Output is correct
19 Correct 125 ms 235212 KB Output is correct
20 Correct 114 ms 235124 KB Output is correct
21 Correct 119 ms 235096 KB Output is correct
22 Correct 113 ms 235144 KB Output is correct
23 Correct 117 ms 235152 KB Output is correct
24 Correct 131 ms 235024 KB Output is correct
25 Correct 122 ms 235228 KB Output is correct
26 Correct 129 ms 235028 KB Output is correct
27 Correct 133 ms 235140 KB Output is correct
28 Correct 125 ms 235056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 235080 KB Output is correct
2 Correct 109 ms 235024 KB Output is correct
3 Correct 106 ms 235056 KB Output is correct
4 Correct 106 ms 235084 KB Output is correct
5 Correct 112 ms 235160 KB Output is correct
6 Correct 107 ms 235064 KB Output is correct
7 Correct 109 ms 235108 KB Output is correct
8 Correct 121 ms 235148 KB Output is correct
9 Correct 110 ms 235248 KB Output is correct
10 Correct 118 ms 235044 KB Output is correct
11 Correct 112 ms 235140 KB Output is correct
12 Correct 113 ms 235132 KB Output is correct
13 Correct 113 ms 235100 KB Output is correct
14 Correct 112 ms 235132 KB Output is correct
15 Correct 115 ms 235072 KB Output is correct
16 Correct 117 ms 235148 KB Output is correct
17 Correct 114 ms 235144 KB Output is correct
18 Correct 119 ms 235088 KB Output is correct
19 Correct 125 ms 235212 KB Output is correct
20 Correct 114 ms 235124 KB Output is correct
21 Correct 119 ms 235096 KB Output is correct
22 Correct 113 ms 235144 KB Output is correct
23 Correct 117 ms 235152 KB Output is correct
24 Correct 131 ms 235024 KB Output is correct
25 Correct 122 ms 235228 KB Output is correct
26 Correct 129 ms 235028 KB Output is correct
27 Correct 133 ms 235140 KB Output is correct
28 Correct 125 ms 235056 KB Output is correct
29 Correct 123 ms 235148 KB Output is correct
30 Correct 126 ms 235092 KB Output is correct
31 Correct 123 ms 235056 KB Output is correct
32 Correct 124 ms 235120 KB Output is correct
33 Correct 115 ms 235120 KB Output is correct
34 Correct 129 ms 235112 KB Output is correct
35 Correct 145 ms 235104 KB Output is correct
36 Correct 122 ms 235144 KB Output is correct
37 Correct 113 ms 235148 KB Output is correct
38 Correct 115 ms 235124 KB Output is correct
39 Correct 116 ms 235148 KB Output is correct
40 Correct 112 ms 235148 KB Output is correct
41 Correct 114 ms 235084 KB Output is correct
42 Correct 113 ms 235092 KB Output is correct
43 Correct 126 ms 235088 KB Output is correct
44 Correct 114 ms 235084 KB Output is correct
45 Correct 120 ms 235052 KB Output is correct
46 Correct 114 ms 235084 KB Output is correct
47 Correct 117 ms 235144 KB Output is correct
48 Correct 116 ms 235084 KB Output is correct
49 Correct 114 ms 235220 KB Output is correct
50 Correct 115 ms 235040 KB Output is correct
51 Correct 116 ms 235056 KB Output is correct
52 Correct 115 ms 235304 KB Output is correct
53 Correct 119 ms 235048 KB Output is correct
54 Correct 116 ms 235268 KB Output is correct
55 Correct 114 ms 235128 KB Output is correct
56 Correct 114 ms 235108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 366 ms 389696 KB Output is correct
2 Correct 343 ms 394832 KB Output is correct
3 Correct 366 ms 394520 KB Output is correct
4 Correct 366 ms 395840 KB Output is correct
5 Correct 354 ms 395700 KB Output is correct
6 Correct 352 ms 395864 KB Output is correct
7 Correct 369 ms 395276 KB Output is correct
8 Correct 375 ms 395592 KB Output is correct
9 Correct 352 ms 394692 KB Output is correct
10 Correct 356 ms 394476 KB Output is correct
11 Correct 352 ms 395952 KB Output is correct
12 Correct 353 ms 394640 KB Output is correct
13 Correct 115 ms 235084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 235080 KB Output is correct
2 Correct 109 ms 235024 KB Output is correct
3 Correct 106 ms 235056 KB Output is correct
4 Correct 106 ms 235084 KB Output is correct
5 Correct 112 ms 235160 KB Output is correct
6 Correct 107 ms 235064 KB Output is correct
7 Correct 109 ms 235108 KB Output is correct
8 Correct 121 ms 235148 KB Output is correct
9 Correct 110 ms 235248 KB Output is correct
10 Correct 118 ms 235044 KB Output is correct
11 Correct 112 ms 235140 KB Output is correct
12 Correct 113 ms 235132 KB Output is correct
13 Correct 113 ms 235100 KB Output is correct
14 Correct 112 ms 235132 KB Output is correct
15 Correct 115 ms 235072 KB Output is correct
16 Correct 117 ms 235148 KB Output is correct
17 Correct 114 ms 235144 KB Output is correct
18 Correct 119 ms 235088 KB Output is correct
19 Correct 125 ms 235212 KB Output is correct
20 Correct 114 ms 235124 KB Output is correct
21 Correct 119 ms 235096 KB Output is correct
22 Correct 113 ms 235144 KB Output is correct
23 Correct 117 ms 235152 KB Output is correct
24 Correct 131 ms 235024 KB Output is correct
25 Correct 122 ms 235228 KB Output is correct
26 Correct 129 ms 235028 KB Output is correct
27 Correct 133 ms 235140 KB Output is correct
28 Correct 125 ms 235056 KB Output is correct
29 Correct 123 ms 235148 KB Output is correct
30 Correct 126 ms 235092 KB Output is correct
31 Correct 123 ms 235056 KB Output is correct
32 Correct 124 ms 235120 KB Output is correct
33 Correct 115 ms 235120 KB Output is correct
34 Correct 129 ms 235112 KB Output is correct
35 Correct 145 ms 235104 KB Output is correct
36 Correct 122 ms 235144 KB Output is correct
37 Correct 113 ms 235148 KB Output is correct
38 Correct 115 ms 235124 KB Output is correct
39 Correct 116 ms 235148 KB Output is correct
40 Correct 112 ms 235148 KB Output is correct
41 Correct 114 ms 235084 KB Output is correct
42 Correct 113 ms 235092 KB Output is correct
43 Correct 126 ms 235088 KB Output is correct
44 Correct 114 ms 235084 KB Output is correct
45 Correct 120 ms 235052 KB Output is correct
46 Correct 114 ms 235084 KB Output is correct
47 Correct 117 ms 235144 KB Output is correct
48 Correct 116 ms 235084 KB Output is correct
49 Correct 114 ms 235220 KB Output is correct
50 Correct 115 ms 235040 KB Output is correct
51 Correct 116 ms 235056 KB Output is correct
52 Correct 115 ms 235304 KB Output is correct
53 Correct 119 ms 235048 KB Output is correct
54 Correct 116 ms 235268 KB Output is correct
55 Correct 114 ms 235128 KB Output is correct
56 Correct 114 ms 235108 KB Output is correct
57 Correct 115 ms 235240 KB Output is correct
58 Correct 119 ms 235184 KB Output is correct
59 Correct 115 ms 235224 KB Output is correct
60 Correct 119 ms 235180 KB Output is correct
61 Correct 114 ms 235216 KB Output is correct
62 Correct 114 ms 235240 KB Output is correct
63 Correct 113 ms 235308 KB Output is correct
64 Correct 115 ms 235284 KB Output is correct
65 Correct 122 ms 235224 KB Output is correct
66 Correct 119 ms 235212 KB Output is correct
67 Correct 116 ms 235156 KB Output is correct
68 Correct 116 ms 235192 KB Output is correct
69 Correct 114 ms 235220 KB Output is correct
70 Correct 112 ms 235252 KB Output is correct
71 Correct 112 ms 235172 KB Output is correct
72 Correct 114 ms 235260 KB Output is correct
73 Correct 116 ms 235312 KB Output is correct
74 Correct 112 ms 235288 KB Output is correct
75 Correct 125 ms 235284 KB Output is correct
76 Correct 115 ms 235232 KB Output is correct
77 Correct 116 ms 235160 KB Output is correct
78 Correct 112 ms 235244 KB Output is correct
79 Correct 112 ms 235228 KB Output is correct
80 Correct 112 ms 235212 KB Output is correct
81 Correct 115 ms 235288 KB Output is correct
82 Correct 116 ms 235232 KB Output is correct
83 Correct 112 ms 235112 KB Output is correct
84 Correct 114 ms 235104 KB Output is correct
85 Correct 125 ms 235100 KB Output is correct
86 Correct 168 ms 235088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 235080 KB Output is correct
2 Correct 109 ms 235024 KB Output is correct
3 Correct 106 ms 235056 KB Output is correct
4 Correct 106 ms 235084 KB Output is correct
5 Correct 112 ms 235160 KB Output is correct
6 Correct 107 ms 235064 KB Output is correct
7 Correct 109 ms 235108 KB Output is correct
8 Correct 121 ms 235148 KB Output is correct
9 Correct 110 ms 235248 KB Output is correct
10 Correct 118 ms 235044 KB Output is correct
11 Correct 112 ms 235140 KB Output is correct
12 Correct 113 ms 235132 KB Output is correct
13 Correct 113 ms 235100 KB Output is correct
14 Correct 112 ms 235132 KB Output is correct
15 Correct 115 ms 235072 KB Output is correct
16 Correct 117 ms 235148 KB Output is correct
17 Correct 114 ms 235144 KB Output is correct
18 Correct 119 ms 235088 KB Output is correct
19 Correct 125 ms 235212 KB Output is correct
20 Correct 114 ms 235124 KB Output is correct
21 Correct 119 ms 235096 KB Output is correct
22 Correct 113 ms 235144 KB Output is correct
23 Correct 117 ms 235152 KB Output is correct
24 Correct 131 ms 235024 KB Output is correct
25 Correct 122 ms 235228 KB Output is correct
26 Correct 129 ms 235028 KB Output is correct
27 Correct 133 ms 235140 KB Output is correct
28 Correct 125 ms 235056 KB Output is correct
29 Correct 123 ms 235148 KB Output is correct
30 Correct 126 ms 235092 KB Output is correct
31 Correct 123 ms 235056 KB Output is correct
32 Correct 124 ms 235120 KB Output is correct
33 Correct 115 ms 235120 KB Output is correct
34 Correct 129 ms 235112 KB Output is correct
35 Correct 145 ms 235104 KB Output is correct
36 Correct 122 ms 235144 KB Output is correct
37 Correct 113 ms 235148 KB Output is correct
38 Correct 115 ms 235124 KB Output is correct
39 Correct 116 ms 235148 KB Output is correct
40 Correct 112 ms 235148 KB Output is correct
41 Correct 114 ms 235084 KB Output is correct
42 Correct 113 ms 235092 KB Output is correct
43 Correct 126 ms 235088 KB Output is correct
44 Correct 114 ms 235084 KB Output is correct
45 Correct 120 ms 235052 KB Output is correct
46 Correct 114 ms 235084 KB Output is correct
47 Correct 117 ms 235144 KB Output is correct
48 Correct 116 ms 235084 KB Output is correct
49 Correct 114 ms 235220 KB Output is correct
50 Correct 115 ms 235040 KB Output is correct
51 Correct 116 ms 235056 KB Output is correct
52 Correct 115 ms 235304 KB Output is correct
53 Correct 119 ms 235048 KB Output is correct
54 Correct 116 ms 235268 KB Output is correct
55 Correct 114 ms 235128 KB Output is correct
56 Correct 114 ms 235108 KB Output is correct
57 Correct 366 ms 389696 KB Output is correct
58 Correct 343 ms 394832 KB Output is correct
59 Correct 366 ms 394520 KB Output is correct
60 Correct 366 ms 395840 KB Output is correct
61 Correct 354 ms 395700 KB Output is correct
62 Correct 352 ms 395864 KB Output is correct
63 Correct 369 ms 395276 KB Output is correct
64 Correct 375 ms 395592 KB Output is correct
65 Correct 352 ms 394692 KB Output is correct
66 Correct 356 ms 394476 KB Output is correct
67 Correct 352 ms 395952 KB Output is correct
68 Correct 353 ms 394640 KB Output is correct
69 Correct 115 ms 235084 KB Output is correct
70 Correct 115 ms 235240 KB Output is correct
71 Correct 119 ms 235184 KB Output is correct
72 Correct 115 ms 235224 KB Output is correct
73 Correct 119 ms 235180 KB Output is correct
74 Correct 114 ms 235216 KB Output is correct
75 Correct 114 ms 235240 KB Output is correct
76 Correct 113 ms 235308 KB Output is correct
77 Correct 115 ms 235284 KB Output is correct
78 Correct 122 ms 235224 KB Output is correct
79 Correct 119 ms 235212 KB Output is correct
80 Correct 116 ms 235156 KB Output is correct
81 Correct 116 ms 235192 KB Output is correct
82 Correct 114 ms 235220 KB Output is correct
83 Correct 112 ms 235252 KB Output is correct
84 Correct 112 ms 235172 KB Output is correct
85 Correct 114 ms 235260 KB Output is correct
86 Correct 116 ms 235312 KB Output is correct
87 Correct 112 ms 235288 KB Output is correct
88 Correct 125 ms 235284 KB Output is correct
89 Correct 115 ms 235232 KB Output is correct
90 Correct 116 ms 235160 KB Output is correct
91 Correct 112 ms 235244 KB Output is correct
92 Correct 112 ms 235228 KB Output is correct
93 Correct 112 ms 235212 KB Output is correct
94 Correct 115 ms 235288 KB Output is correct
95 Correct 116 ms 235232 KB Output is correct
96 Correct 112 ms 235112 KB Output is correct
97 Correct 114 ms 235104 KB Output is correct
98 Correct 125 ms 235100 KB Output is correct
99 Correct 168 ms 235088 KB Output is correct
100 Correct 499 ms 327400 KB Output is correct
101 Correct 506 ms 327208 KB Output is correct
102 Correct 488 ms 326036 KB Output is correct
103 Correct 444 ms 327320 KB Output is correct
104 Correct 438 ms 327176 KB Output is correct
105 Correct 373 ms 348876 KB Output is correct
106 Correct 377 ms 348484 KB Output is correct
107 Correct 353 ms 348784 KB Output is correct
108 Correct 356 ms 349376 KB Output is correct
109 Correct 372 ms 349708 KB Output is correct
110 Correct 433 ms 326600 KB Output is correct
111 Correct 435 ms 324452 KB Output is correct
112 Correct 408 ms 323908 KB Output is correct
113 Correct 418 ms 323008 KB Output is correct
114 Correct 430 ms 324792 KB Output is correct
115 Correct 378 ms 395848 KB Output is correct
116 Correct 369 ms 395096 KB Output is correct
117 Correct 357 ms 395616 KB Output is correct
118 Correct 391 ms 395080 KB Output is correct
119 Correct 373 ms 394780 KB Output is correct
120 Correct 425 ms 325320 KB Output is correct
121 Correct 430 ms 325404 KB Output is correct
122 Correct 423 ms 323876 KB Output is correct
123 Correct 429 ms 325704 KB Output is correct
124 Correct 384 ms 355164 KB Output is correct
125 Correct 397 ms 354536 KB Output is correct
126 Correct 385 ms 353988 KB Output is correct
127 Correct 390 ms 354688 KB Output is correct
128 Correct 283 ms 282904 KB Output is correct
129 Correct 274 ms 282524 KB Output is correct
130 Correct 280 ms 282828 KB Output is correct
131 Correct 123 ms 235088 KB Output is correct