提出 #68376172
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = (1ll << 60);
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
pair<ll, ll> f(string S, int v){
array<int, 4> a;
{
int tmp = v;
rep(i, 0, 4){
a[3 - i] = (tmp & 1);
tmp /= 2;
}
}
auto g = [&](int ind) -> int {
return a[(S[ind] - '0') * 2 + S[ind + 1] - '0'];
};
ll N = S.size();
if (N == 1){
if (S == "1"){
return {1, 1};
}
return {-1, 0};
}
if (a[1] == 1 && a[2] == 0){
reverse(S.begin(), S.end());
return f(S, v - 2);
}
ll L = -1, M = 0;
auto lower_2 = [&]() -> void {
rep(i, 0, N) if (S[i] == '1') L = 1, M++;
rep(i, 0, N - 1) if (g(i)) L = 2, M++;
};
if (N == 2){
lower_2();
return {L, M};
}
// 0
if (v == 0){
rep(i, 0, N) if (S[i] == '1') L = 1, M++;
return {L, M};
}
// 1
// 1 のみ
if (v == 1){
for (ll l = 0, r = 0; l < N; l = r + 1, r = l){
while (r != N && S[r] == '1') r++;
if (r - l){
chmax(L, r - l);
M += (r - l) * (r - l + 1) / 2;
}
}
return {L, M};
}
// 2 (4)
// 1 から始まる
// 1100000... 以外
if (v == 2){
lower_2();
rep(i, 0, N - 2){
if (S[i] == '1'){
if (S[i + 1] == '0') {
chmax(L, N - i);
M += N - 2 - i;
}
else{
int tmp = i + 2;
while (tmp != N && S[tmp] == '0') tmp++;
if (tmp != N){
M += N - tmp;
chmax(L, N - i);
}
}
}
}
return {L, M};
}
// 3. 5
// 左が 1
if (v == 3){
rep(i, 0, N){
if (S[i] == '1'){
chmax(L, (ll)(N - i));
M += N - i;
}
}
return {L, M};
}
// 6
// 1 がきすー
if (v == 6){
ll A = 1, X = 0;
ll B = 0, Y = INF;
rep(i, 0, N){
if (S[i] == '1'){
swap(A, B);
swap(X, Y);
}
M += B;
chmax(L, i + 1 - Y);
A++;
chmin(X, i + 1ll);
}
return {L, M};
}
// 7
// all 0 でない
// or
if (v == 7){
for (auto &c : S) c = (c == '1' ? '0' : '1');
auto [l, m] = f(S, 1);
M = N * (N + 1) / 2 - m;
L = N;
if (M == 0) L = -1;
return {L, M};
}
// 8
if (v == 8){
rep(ran, 1, N + 1){
if (ran >= 4){
chmax(L, (ll)ran);
M += N + 1 - ran;
continue;
}
rep(i, 0, N - ran + 1){
vector dp(2, vector(ran, vector<bool>(ran + 1)));
rep(j, 0, ran) dp[S[i + j] - '0'][j][j + 1] = true;
for (int l = ran - 1; l >= 0; l--) rep(r, l + 1, ran + 1){
rep(k, l + 1, r) rep(x, 0, 2) rep(y, 0, 2){
if (dp[x][l][k] && dp[y][k][r]){
dp[1 - (x | y)][l][r] = true;
}
}
}
if (dp[1][0][ran]) L = ran, M++;
}
}
return {L, M};
}
// 9
// 0 がぐースー
if (v == 9){
ll A = 1, X = 0;
ll B = 0, Y = INF;
rep(i, 0, N){
if (S[i] == '0'){
swap(A, B);
swap(X, Y);
}
M += A;
chmax(L, i + 1 - X);
A++;
chmin(X, i + 1ll);
}
return {L, M};
}
// 10
if (v == 10){
lower_2();
M += N * (N + 1) / 2 - N - (N - 1);
L = N;
return {L, M};
}
if (v == 11){
// L のチェック
{
L = N - 1;
if (S[0] == '1') L = N;
rep(i, 1, N) if (S[i] == '0') L = N;
}
M += N * (N + 1) / 2;
for (int l = 0, r = 0; l < N; l = r){
if (S[l] == '1'){
r++;
continue;
}
r++;
while (r < N && S[r] == '1') r++;
M -= r - l;
}
return {L, M};
}
if (v == 14){
lower_2();
if (S != "101") L = N;
M += N * (N + 1) / 2 - N - (N - 1);
rep(i, 0, N - 2) if (S.substr(i, 3) == "101") M--;
return {L, M};
}
if (v == 15){
lower_2();
L = N;
M += N * (N + 1) / 2 - N - (N - 1);
return {L, M};
}
assert(false);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
string S;
cin >> S;
rep(i, 0, 16){
auto [L, M] = f(S, i);
cout << L << " " << M << "\n";
}
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
650 / 650 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 01_small_10.txt, 01_small_11.txt, 01_small_12.txt, 01_small_13.txt, 01_small_14.txt, 01_small_15.txt, 01_small_16.txt, 01_small_17.txt, 01_small_18.txt, 01_small_19.txt, 01_small_20.txt, 01_small_21.txt, 01_small_22.txt, 01_small_23.txt, 01_small_24.txt, 01_small_25.txt, 01_small_26.txt, 01_small_27.txt, 01_small_28.txt, 01_small_29.txt, 01_small_30.txt, 01_small_31.txt, 01_small_32.txt, 01_small_33.txt, 01_small_34.txt, 01_small_35.txt, 01_small_36.txt, 01_small_37.txt, 01_small_38.txt, 01_small_39.txt, 01_small_40.txt, 01_small_41.txt, 01_small_42.txt, 01_small_43.txt, 01_small_44.txt, 01_small_45.txt, 01_small_46.txt, 01_small_47.txt, 01_small_48.txt, 01_small_49.txt, 01_small_50.txt, 01_small_51.txt, 01_small_52.txt, 01_small_53.txt, 01_small_54.txt, 01_small_55.txt, 01_small_56.txt, 01_small_57.txt, 01_small_58.txt, 01_small_59.txt, 01_small_60.txt, 01_small_61.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 03_corner_00.txt, 03_corner_01.txt, 03_corner_02.txt, 03_corner_03.txt, 03_corner_04.txt, 03_corner_05.txt, 03_corner_06.txt, 03_corner_07.txt, 03_corner_08.txt, 03_corner_09.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
1 ms |
3592 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3536 KiB |
| 00_sample_02.txt |
AC |
1 ms |
3504 KiB |
| 01_small_00.txt |
AC |
1 ms |
3508 KiB |
| 01_small_01.txt |
AC |
1 ms |
3460 KiB |
| 01_small_02.txt |
AC |
1 ms |
3508 KiB |
| 01_small_03.txt |
AC |
1 ms |
3424 KiB |
| 01_small_04.txt |
AC |
1 ms |
3512 KiB |
| 01_small_05.txt |
AC |
1 ms |
3468 KiB |
| 01_small_06.txt |
AC |
1 ms |
3536 KiB |
| 01_small_07.txt |
AC |
1 ms |
3532 KiB |
| 01_small_08.txt |
AC |
1 ms |
3608 KiB |
| 01_small_09.txt |
AC |
1 ms |
3508 KiB |
| 01_small_10.txt |
AC |
1 ms |
3424 KiB |
| 01_small_11.txt |
AC |
1 ms |
3476 KiB |
| 01_small_12.txt |
AC |
1 ms |
3624 KiB |
| 01_small_13.txt |
AC |
1 ms |
3464 KiB |
| 01_small_14.txt |
AC |
1 ms |
3532 KiB |
| 01_small_15.txt |
AC |
1 ms |
3536 KiB |
| 01_small_16.txt |
AC |
1 ms |
3660 KiB |
| 01_small_17.txt |
AC |
1 ms |
3512 KiB |
| 01_small_18.txt |
AC |
1 ms |
3512 KiB |
| 01_small_19.txt |
AC |
1 ms |
3540 KiB |
| 01_small_20.txt |
AC |
1 ms |
3464 KiB |
| 01_small_21.txt |
AC |
1 ms |
3420 KiB |
| 01_small_22.txt |
AC |
1 ms |
3532 KiB |
| 01_small_23.txt |
AC |
1 ms |
3452 KiB |
| 01_small_24.txt |
AC |
1 ms |
3524 KiB |
| 01_small_25.txt |
AC |
1 ms |
3452 KiB |
| 01_small_26.txt |
AC |
1 ms |
3424 KiB |
| 01_small_27.txt |
AC |
1 ms |
3512 KiB |
| 01_small_28.txt |
AC |
1 ms |
3540 KiB |
| 01_small_29.txt |
AC |
1 ms |
3528 KiB |
| 01_small_30.txt |
AC |
1 ms |
3464 KiB |
| 01_small_31.txt |
AC |
1 ms |
3424 KiB |
| 01_small_32.txt |
AC |
1 ms |
3460 KiB |
| 01_small_33.txt |
AC |
1 ms |
3532 KiB |
| 01_small_34.txt |
AC |
1 ms |
3468 KiB |
| 01_small_35.txt |
AC |
1 ms |
3524 KiB |
| 01_small_36.txt |
AC |
1 ms |
3456 KiB |
| 01_small_37.txt |
AC |
1 ms |
3512 KiB |
| 01_small_38.txt |
AC |
1 ms |
3616 KiB |
| 01_small_39.txt |
AC |
1 ms |
3452 KiB |
| 01_small_40.txt |
AC |
1 ms |
3512 KiB |
| 01_small_41.txt |
AC |
1 ms |
3536 KiB |
| 01_small_42.txt |
AC |
1 ms |
3608 KiB |
| 01_small_43.txt |
AC |
1 ms |
3468 KiB |
| 01_small_44.txt |
AC |
1 ms |
3452 KiB |
| 01_small_45.txt |
AC |
1 ms |
3592 KiB |
| 01_small_46.txt |
AC |
1 ms |
3592 KiB |
| 01_small_47.txt |
AC |
1 ms |
3452 KiB |
| 01_small_48.txt |
AC |
1 ms |
3408 KiB |
| 01_small_49.txt |
AC |
1 ms |
3656 KiB |
| 01_small_50.txt |
AC |
1 ms |
3616 KiB |
| 01_small_51.txt |
AC |
1 ms |
3532 KiB |
| 01_small_52.txt |
AC |
1 ms |
3404 KiB |
| 01_small_53.txt |
AC |
1 ms |
3536 KiB |
| 01_small_54.txt |
AC |
1 ms |
3524 KiB |
| 01_small_55.txt |
AC |
1 ms |
3532 KiB |
| 01_small_56.txt |
AC |
1 ms |
3616 KiB |
| 01_small_57.txt |
AC |
1 ms |
3592 KiB |
| 01_small_58.txt |
AC |
1 ms |
3532 KiB |
| 01_small_59.txt |
AC |
1 ms |
3508 KiB |
| 01_small_60.txt |
AC |
1 ms |
3520 KiB |
| 01_small_61.txt |
AC |
1 ms |
3472 KiB |
| 02_random_00.txt |
AC |
145 ms |
3896 KiB |
| 02_random_01.txt |
AC |
147 ms |
3932 KiB |
| 02_random_02.txt |
AC |
134 ms |
3832 KiB |
| 02_random_03.txt |
AC |
147 ms |
3924 KiB |
| 02_random_04.txt |
AC |
136 ms |
3976 KiB |
| 02_random_05.txt |
AC |
148 ms |
3824 KiB |
| 02_random_06.txt |
AC |
134 ms |
3780 KiB |
| 02_random_07.txt |
AC |
147 ms |
3924 KiB |
| 02_random_08.txt |
AC |
138 ms |
3964 KiB |
| 02_random_09.txt |
AC |
148 ms |
3928 KiB |
| 03_corner_00.txt |
AC |
126 ms |
4052 KiB |
| 03_corner_01.txt |
AC |
125 ms |
4016 KiB |
| 03_corner_02.txt |
AC |
128 ms |
3904 KiB |
| 03_corner_03.txt |
AC |
127 ms |
3928 KiB |
| 03_corner_04.txt |
AC |
134 ms |
3860 KiB |
| 03_corner_05.txt |
AC |
128 ms |
3924 KiB |
| 03_corner_06.txt |
AC |
126 ms |
3932 KiB |
| 03_corner_07.txt |
AC |
127 ms |
3848 KiB |
| 03_corner_08.txt |
AC |
127 ms |
3856 KiB |
| 03_corner_09.txt |
AC |
125 ms |
3860 KiB |