結果

問題 No.1694 ZerOne
ユーザー hourenhouren
提出日時 2021-10-01 23:34:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,455 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 180,280 KB
実行使用メモリ 821,300 KB
最終ジャッジ日時 2023-09-26 22:45:56
合計ジャッジ時間 7,006 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()

set<P> seen;
int ans = 1,n;
void dfs(string ns){
    vector<vector<vector<int>>> ppct(n/2+1,vector<vector<int>>(n/2+1));
    for(int i=2;i<=n/2;i++){
        int onecnt = 0;
        rep(j,i) onecnt += (ns[j] == '1');
        ppct[i][onecnt].push_back(0);
        for(int j=i;j<n;j++){
            onecnt -= (ns[j-i] == '1');
            onecnt += (ns[j] == '1');
            ppct[i][onecnt].push_back(j-i+1);
        }
    }
    for(int i=2;i<=n/2;i++){
        for(auto vec:ppct[i]){
            int siz = vec.size();
            rep(j,siz-1){
                for(int k=j+1;k<siz;k++){
                    if(vec[k]-vec[j]<i) continue;
                    if(seen.count(make_pair(vec[j]+i-2,vec[k]+i-2))) continue;
                    string sj = ns.substr(vec[j],i), sk = ns.substr(vec[k],i);
                    if(sj==sk) continue;
                    ans++;
                    //cout << i << " " << vec[j] << " " << vec[k] << endl;
                    seen.insert(make_pair(vec[j],vec[k]));
                    string nns = ns;
                    nns.replace(vec[j],i,sk); nns.replace(vec[k],i,sj);
                    dfs(nns);
                }
            }
        }
    }
}

int main(){
    string s;
    cin >> s;
    n = s.size();
    dfs(s);
    /*vector<vector<vector<int>>> ppct(n/2+1,vector<vector<int>>(n/2+1));
    for(int i=2;i<=n/2;i++){
        int onecnt = 0;
        rep(j,i) onecnt += (s[j] == '1');
        ppct[i][onecnt].push_back(0);
        for(int j=i;j<n;j++){
            onecnt -= (s[j-i] == '1');
            onecnt += (s[j] == '1');
            ppct[i][onecnt].push_back(j-i+1);
        }
    }
    
    for(int i=2;i<=n/2;i++){
        for(auto vec:ppct[i]){
            int siz = vec.size();
            rep(j,siz-1){
                for(int k=j+1;k<siz;k++){
                    if(vec[k]-vec[j]<i) continue;
                    if(seen.count(make_pair(vec[j]+i-2,vec[k]+i-2))) continue;
                    if(s.substr(vec[j],i)==s.substr(vec[k],i)) continue;
                    ans++;
                    //cout << i << " " << vec[j] << " " << vec[k] << endl;
                    seen.insert(make_pair(vec[j],vec[k]));
                }
            }
        }
    }*/
    cout << ans << endl;
    return 0;
}
0