提出 #14590368


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;

int main(){
    ll res = 0;
    int rs = 0, gs = 0, bs = 0;
    int n;
    string s;
    cin >> n >> s;
    rep(i, n) {
        if(s[i] == 'R') {
            rs += 1;
        }
        if(s[i] == 'G') {
            gs += 1;
        }
        if(s[i] == 'B') {
            bs += 1;
        }
    }
    int r[rs], g[gs], b[bs];
    rs = 0, gs = 0, bs = 0;
    rep(i, n) {
        if(s[i] == 'R') {
            r[rs] = i;
            rs += 1;
        }
        if(s[i] == 'G') {
            g[gs] = i;
            gs += 1;
        }
        if(s[i] == 'B') {
            b[bs] = i;
            bs += 1;
        }
    }

    int ma, mi, mid;
    rep(i, rs) {
        rep(j, gs) {
            rep(k, bs) {
                if(r[i] > g[j]) {
                    if(r[i] > b[k]) {
                        ma = r[i];
                        mi = min(g[j], b[k]);
                        mid = max(g[j], b[k]);
                    } else {
                        ma = b[k];
                        mi = g[j];
                        mid = r[i];
                    }
                } else {
                    if(g[j] > b[k]) {
                        ma = g[j];
                        mi = min(r[i], b[k]);
                        mid = max(r[i], b[k]);
                    } else {
                        ma = b[k];
                        mi = r[i];
                        mid = g[j];
                    }
                }
                if((mid - mi) != (ma - mid)) {
                    res += 1;     
                }
            }
        }
    }
    cout << res << endl;
}

提出情報

提出日時
問題 D - RGB Triplets
ユーザ KeitaKishida0811
言語 C++ (GCC 9.2.1)
得点 0
コード長 1859 Byte
結果 TLE
実行時間 2205 ms
メモリ 3612 KiB

ジャッジ結果

セット名 All Sample
得点 / 配点 0 / 400 0 / 0
結果
AC × 18
TLE × 3
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 7 ms 3460 KiB
sample_02 AC 3 ms 3424 KiB
testcase_0 AC 2 ms 3484 KiB
testcase_1 AC 2 ms 3592 KiB
testcase_10 AC 22 ms 3476 KiB
testcase_11 AC 3 ms 3520 KiB
testcase_12 AC 5 ms 3528 KiB
testcase_13 AC 67 ms 3600 KiB
testcase_14 AC 32 ms 3600 KiB
testcase_15 TLE 2205 ms 3416 KiB
testcase_16 AC 646 ms 3560 KiB
testcase_17 TLE 2205 ms 3320 KiB
testcase_18 TLE 2205 ms 3268 KiB
testcase_2 AC 7 ms 3600 KiB
testcase_3 AC 3 ms 3612 KiB
testcase_4 AC 2 ms 3612 KiB
testcase_5 AC 2 ms 3544 KiB
testcase_6 AC 5 ms 3596 KiB
testcase_7 AC 2 ms 3544 KiB
testcase_8 AC 2 ms 3508 KiB
testcase_9 AC 2 ms 3484 KiB