Contest Duration: - (local time) (100 minutes) Back to Home

Submission #857183

Source Code Expand

Copy
```#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

const int64_t M = 1000000007;

string w;
int n;

int gtbl[4001][4001];

bool check(int l, int r, int s)
{
int sl = (r - l) / s;
for (int ofs = 0; ofs < sl; ofs++) {
for (int seg = 1; seg < s; seg++) {
if (w[l + ofs] != w[l + seg * sl + ofs]) {
return false;
}
}
}
return true;
}

bool is_good(int l, int r)
{
auto &ret = gtbl[l][r];

if (ret >= 0) return ret != 0;
int L = r - l;

ret = 0;
for (int i = 2; i * i <= L; i++) {
if (L % i == 0) continue;

if (check(l, r, i)) return ret = 1;
if (check(l, r, L / i)) return ret = 1;
}

return ret;
}

pair<int, int> tbl[4001][4001];

pair<int, int> solve(int l, int r)
{
auto &ret = tbl[l][r];
if (ret.first >= 0) return ret;

ret.first = 0;
ret.second = 0;

if (r - l == 1) return ret = make_pair(1, 1);
if (is_good(l, r)) return ret = make_pair(1, 1);

for (int m = l + 1; m < r; m++) {
auto ll = solve(l, m);
auto rr = solve(m, l);

if (ret.first == 0 || ret.first > ll.first + rr.first) {
ret.first = ll.first + rr.first;
ret.second = ((int64_t)ll.second * rr.second) % M;
} else if (ret.first == ll.first + rr.first) {
ret.second = (ret.second + ((int64_t)ll.second * rr.second)) % M;
}
}

return ret;
}

int main()
{
cin >> w;
n = w.size();

auto r =  solve(0, n);
cout << r.first << endl;
cout << r.second << endl;

return 0;
}```

#### Submission Info

Submission Time 2016-08-28 22:39:34+0900 F - Best Representation tanakh C++14 (GCC 5.4.1) 0 1811 Byte WA 35 ms 900 KB

#### Judge Result

Score / Max Score 0 / 0 0 / 400 0 / 500
Status
 WA × 3
 WA × 36
 WA × 65
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt
Case Name Status Exec Time Memory
example_01.txt WA 4 ms 256 KB
example_02.txt WA 4 ms 256 KB
example_03.txt WA 4 ms 256 KB
subtask1_01.txt WA 4 ms 256 KB
subtask1_02.txt WA 4 ms 256 KB
subtask1_03.txt WA 4 ms 256 KB
subtask1_04.txt WA 4 ms 256 KB
subtask1_05.txt WA 4 ms 256 KB
subtask1_06.txt WA 4 ms 256 KB
subtask1_07.txt WA 4 ms 256 KB
subtask1_08.txt WA 4 ms 256 KB
subtask1_09.txt WA 4 ms 256 KB
subtask1_10.txt WA 4 ms 256 KB
subtask1_11.txt WA 4 ms 256 KB
subtask1_12.txt WA 4 ms 256 KB
subtask1_13.txt WA 4 ms 256 KB
subtask1_14.txt WA 4 ms 256 KB
subtask1_15.txt WA 4 ms 256 KB
subtask1_16.txt WA 4 ms 256 KB
subtask1_17.txt WA 4 ms 256 KB
subtask1_18.txt WA 4 ms 256 KB
subtask1_19.txt WA 4 ms 256 KB
subtask1_20.txt WA 4 ms 256 KB
subtask1_21.txt WA 4 ms 256 KB
subtask1_22.txt WA 4 ms 256 KB
subtask1_23.txt WA 4 ms 256 KB
subtask1_24.txt WA 4 ms 256 KB
subtask1_25.txt WA 4 ms 256 KB
subtask1_26.txt WA 4 ms 256 KB
subtask1_27.txt WA 4 ms 256 KB
subtask1_28.txt WA 4 ms 256 KB
subtask1_29.txt WA 4 ms 256 KB
subtask1_30.txt WA 4 ms 256 KB
subtask1_31.txt WA 4 ms 256 KB
subtask1_32.txt WA 4 ms 256 KB
subtask1_33.txt WA 6 ms 256 KB
subtask2_01.txt WA 26 ms 900 KB
subtask2_02.txt WA 32 ms 900 KB
subtask2_03.txt WA 31 ms 900 KB
subtask2_04.txt WA 32 ms 900 KB
subtask2_05.txt WA 32 ms 900 KB
subtask2_06.txt WA 32 ms 900 KB
subtask2_07.txt WA 35 ms 900 KB
subtask2_08.txt WA 32 ms 900 KB
subtask2_09.txt WA 32 ms 900 KB
subtask2_10.txt WA 31 ms 900 KB
subtask2_11.txt WA 31 ms 900 KB
subtask2_12.txt WA 31 ms 900 KB
subtask2_13.txt WA 32 ms 900 KB
subtask2_14.txt WA 32 ms 900 KB
subtask2_15.txt WA 32 ms 900 KB
subtask2_16.txt WA 32 ms 900 KB
subtask2_17.txt WA 31 ms 900 KB
subtask2_18.txt WA 32 ms 900 KB
subtask2_19.txt WA 31 ms 900 KB
subtask2_20.txt WA 31 ms 900 KB
subtask2_21.txt WA 30 ms 900 KB
subtask2_22.txt WA 32 ms 900 KB
subtask2_23.txt WA 32 ms 900 KB
subtask2_24.txt WA 27 ms 900 KB
subtask2_25.txt WA 29 ms 900 KB
subtask2_26.txt WA 30 ms 900 KB
subtask2_27.txt WA 27 ms 900 KB
subtask2_28.txt WA 19 ms 900 KB
subtask2_29.txt WA 26 ms 900 KB