提出 #11935231


ソースコード 拡げる

#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

string S;
int N;
// pos
vector<set<int>> v;

// j - i \ne k-j を満たす数を負数として返す。
ll go() {
    ll ans = 0;
    for(const auto &i:v[0]) {
        // find start
        auto sj = upper_bound(ALL(v[1]),i);
        for(auto j = sj; j != v[1].end(); j ++) {
            int nk = 2*(*j) - i;
            if (   *j < nk && v[2].count(nk) == 1)  ans--;
        }
    }
    return ans;
}



void solve() {
    v.resize(3);
    cin >> N;
    cin >> S;
    REP(i,N) {
        if (S[i]== 'R') v[0].insert(i);
        if (S[i]=='G') v[1].insert(i);
        if (S[i]=='B') v[2].insert(i);
    }
    ll ans = v[0].size()*v[1].size()*v[2].size();
    // iter_swapでi,j,kとR,G,Bの袋の割り当て方を全部だしている。
    REP(i,3) {
        ans += go();
        iter_swap(v.begin()+1,v.begin()+2);
        ans += go();
        iter_swap(v.begin(),v.begin()+1);
    }
    cout << ans << endl;

}

int main() {
    solve();
    return 0;
}

提出情報

提出日時
問題 D - RGB Triplets
ユーザ reud
言語 C++ (GCC 9.2.1)
得点 400
コード長 1510 Byte
結果 AC
実行時間 337 ms
メモリ 3816 KiB

ジャッジ結果

セット名 All Sample
得点 / 配点 400 / 400 0 / 0
結果
AC × 21
AC × 2
セット名 テストケース
All sample_01, sample_02, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_2, testcase_3, testcase_4, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9
Sample sample_01, sample_02
ケース名 結果 実行時間 メモリ
sample_01 AC 3 ms 3516 KiB
sample_02 AC 2 ms 3644 KiB
testcase_0 AC 2 ms 3600 KiB
testcase_1 AC 2 ms 3532 KiB
testcase_10 AC 9 ms 3552 KiB
testcase_11 AC 2 ms 3604 KiB
testcase_12 AC 3 ms 3536 KiB
testcase_13 AC 22 ms 3668 KiB
testcase_14 AC 14 ms 3608 KiB
testcase_15 AC 232 ms 3684 KiB
testcase_16 AC 92 ms 3636 KiB
testcase_17 AC 337 ms 3816 KiB
testcase_18 AC 214 ms 3724 KiB
testcase_2 AC 2 ms 3644 KiB
testcase_3 AC 2 ms 3576 KiB
testcase_4 AC 2 ms 3508 KiB
testcase_5 AC 6 ms 3520 KiB
testcase_6 AC 2 ms 3512 KiB
testcase_7 AC 2 ms 3620 KiB
testcase_8 AC 2 ms 3596 KiB
testcase_9 AC 2 ms 3524 KiB