Skip to content

Commit 82e8387

Browse files
committed
[atcoder] Add abc D
1 parent cd9811a commit 82e8387

File tree

8 files changed

+170
-0
lines changed

8 files changed

+170
-0
lines changed

atcoder/abc122/D.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <string>
4+
using namespace std;
5+
6+
const long long MOD = 1'000'000'000 + 9;
7+
8+
long long power(long long m, long long n) {
9+
long long ret = 1;
10+
for (int i = 0; i < n; ++i)
11+
ret = (ret * m) % MOD;
12+
return ret;
13+
}
14+
15+
int main() {
16+
int N;
17+
while (cin >> N) {
18+
vector<string> forbidden = {"AGC", "ACG", "GAC", "ATGC", "AGGC", "AGTC"};
19+
long long ans = 0;
20+
for (int S = 1; S < (1 << forbidden.size()); ++S) {
21+
int len = 0;
22+
for (int i = 0; i < (int)forbidden.size(); ++i) {
23+
if ((S >> i) & 1) {
24+
len += forbidden[i].length();
25+
}
26+
}
27+
if (N - len >= 0) {
28+
long long pattern = power(4, N - len) * (N - len + 1) % MOD;
29+
if (S == 3) {
30+
// GACG
31+
pattern = (pattern + MOD - power(4, N - 4)) % MOD;
32+
}
33+
cout << "pattern=" << pattern << endl;
34+
if (__builtin_popcount(S) % 2 == 1) {
35+
ans = (ans + pattern) % MOD;
36+
} else {
37+
ans = (ans - pattern + MOD) % MOD;
38+
}
39+
}
40+
}
41+
long long all = power(4, N);
42+
cout << (all - ans + MOD) % MOD << endl;
43+
}
44+
}

atcoder/abc122/D.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
3
2+
4
3+
100

atcoder/abc123/D.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
#include <functional>
5+
using namespace std;
6+
7+
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
8+
9+
int main() {
10+
int X, Y, Z, K;
11+
while (cin >> X >> Y >> Z >> K) {
12+
vector<long long> A(X), B(Y), C(Z);
13+
REP(i, X) cin >> A[i];
14+
REP(i, Y) cin >> B[i];
15+
REP(i, Z) cin >> C[i];
16+
sort(A.begin(), A.end(), greater<long long>());
17+
18+
vector<long long> BC;
19+
REP(y, Y) REP(z, Z) BC.push_back(B[y] + C[z]);
20+
sort(BC.begin(), BC.end(), greater<long long>());
21+
22+
vector<long long> ABC;
23+
REP(x, X) REP(k, min(K, (int)BC.size())) {
24+
ABC.push_back(A[x] + BC[k]);
25+
}
26+
sort(ABC.begin(), ABC.end(), greater<long long>());
27+
28+
REP(k, K) cout << ABC[k] << '\n';
29+
}
30+
}

atcoder/abc123/D.in

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2 2 2 8
2+
4 6
3+
1 5
4+
3 8
5+
6+
3 3 3 5
7+
1 10 100
8+
2 20 200
9+
1 10 100
10+
11+
10 10 10 20
12+
7467038376 5724769290 292794712 2843504496 3381970101 8402252870 249131806 6310293640 6690322794 6082257488
13+
1873977926 2576529623 1144842195 1379118507 6003234687 4925540914 3902539811 3326692703 484657758 2877436338
14+
4975681328 8974383988 2882263257 7690203955 514305523 6679823484 4263279310 585966808 3752282379 620585736

atcoder/abc124/D.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <vector>
4+
#include <string>
5+
using namespace std;
6+
7+
int main() {
8+
int N, K;
9+
while (cin >> N >> K) {
10+
string S; cin >> S;
11+
vector<int> n_segment(N);
12+
bool in_segment = (S[0] == '0');
13+
n_segment[0] = (S[0] == '0');
14+
for (int i = 1; i < N; ++i) {
15+
if (S[i] == '0') {
16+
n_segment[i] = n_segment[i-1] + (in_segment ? 0 : 1);
17+
in_segment = true;
18+
} else {
19+
n_segment[i] = n_segment[i-1];
20+
in_segment = false;
21+
}
22+
}
23+
int answer = 0;
24+
for (int i = 0; i < N; ++i) {
25+
int limit = K + n_segment[i] + (S[i] == '0' ? -1 : 0);
26+
auto it = upper_bound(n_segment.begin() + i, n_segment.end(), limit);
27+
int len = it - (n_segment.begin() + i);
28+
answer = max(answer, len);
29+
}
30+
cout << answer << endl;
31+
}
32+
}

atcoder/abc124/D.in

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
5 1
2+
00010
3+
4+
14 2
5+
11101010110011
6+
7+
1 1
8+
1
9+
10+
12 1
11+
110001100011

atcoder/abc125/D.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
using namespace std;
5+
6+
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
7+
8+
int main() {
9+
int N;
10+
while (cin >> N) {
11+
vector<long long> A(N);
12+
REP(i, N) {
13+
cin >> A[i];
14+
}
15+
16+
vector<vector<long long>> dp(N, vector<long long>(2));
17+
dp[0][0] = A[0];
18+
dp[0][1] = -1e12;
19+
for (int i = 1; i < N; ++i) {
20+
// -1 倍しない場合
21+
dp[i][0] = A[i] + max(dp[i-1][0], dp[i-1][1]);
22+
// -1 倍する場合
23+
dp[i][1] = -A[i] + max(dp[i-1][0] - 2*A[i-1], dp[i-1][1] + 2*A[i-1]);
24+
}
25+
26+
cout << max(dp[N-1][0], dp[N-1][1]) << endl;
27+
}
28+
}

atcoder/abc125/D.in

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
3
2+
-10 5 -4
3+
4+
5
5+
10 -4 -8 -11 3
6+
7+
11
8+
-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000

0 commit comments

Comments
 (0)