Submission #4044638


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<pair<char, int>> runLengthEncoding(string s) {
    int n = s.length();

    vector<pair<char, int>> res;
    char pre = s[0];
    int cnt = 1;
    rep(i, 1, n) {
        if (pre != s[i]) {
            res.push_back({ pre, cnt });
            pre = s[i];
            cnt = 1;
        }
        else cnt++;
    }

    res.push_back({ pre, cnt });
    return res;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/









int N; string S;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> S;

    auto v = runLengthEncoding(S);

    // change
    int n = v.size();
    int ma = -1, id;
    rep(i, 0, n) if(v[i].first == '>' and ma < v[i].second) {
        ma = v[i].second;
        id = i;
    }

    if (ma < 0) {
        v[0].second--;
        v.push_back({ '>', 1 });
    } else {
        v[id].second++;
        v[id + 1].second--;
    }

    // run
    double ans = 0;
    fore(p, v) {
        if (p.first == '-') ans += p.second;
        else {
            rep(k, 0, p.second) ans += 1.0 / (k + 2);
        }
    }
    printf("%.10f\n", ans);
}

Submission Info

Submission Time
Task A - レース (Race)
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 300
Code Size 2391 Byte
Status AC
Exec Time 3 ms
Memory 848 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
in01.txt AC 1 ms 256 KiB
in02.txt AC 1 ms 256 KiB
in03.txt AC 2 ms 512 KiB
in04.txt AC 2 ms 512 KiB
in05.txt AC 2 ms 512 KiB
in06.txt AC 2 ms 512 KiB
in07.txt AC 2 ms 512 KiB
in08.txt AC 2 ms 512 KiB
in09.txt AC 2 ms 512 KiB
in10.txt AC 2 ms 512 KiB
in11.txt AC 2 ms 592 KiB
in12.txt AC 2 ms 720 KiB
in13.txt AC 3 ms 848 KiB
in14.txt AC 3 ms 848 KiB
in15.txt AC 2 ms 512 KiB
in16.txt AC 2 ms 512 KiB
sample_01.txt AC 1 ms 256 KiB
sample_02.txt AC 1 ms 256 KiB
sample_03.txt AC 1 ms 256 KiB