Submission #43908360


Source Code Expand

// clang-format off
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REPI,_REP,)(__VA_ARGS__)
#define _RREP(i,n) RREPI(i,n,0)
#define RREPI(i,a,b) for(int i=int(a);i>=int(b);--i)
#define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
typedef long long ll;
const int INF32 = 1001001001;
const long long INF64 = 1001001001001001001;
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); cout << setprecision(15); }} init;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template<class T> T gcd(T x, T y){ return (x % y) ? gcd(y, x % y) : y; }
template<class T> T lcm(T x, T y){ return x / gcd(x, y) * y; }
template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T> void output(vector<T> v) { for (auto u : v) cout << u << ' '; cout << '\n'; };
void yesno(bool is_ok) { cout << (is_ok ? "yes" : "no") << '\n'; }
void YesNo(bool is_ok) { cout << (is_ok ? "Yes" : "No") << '\n'; }
void YESNO(bool is_ok) { cout << (is_ok ? "YES" : "NO") << '\n'; }

// clang-format on
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int cnt = 0;
    int start = 0;
    vector<pair<int, int>> p;
    REP(i, n) {
        if (cnt == 0) {
            ++cnt;
            start = a[i];
        } else {
            if (a[i] == a[i - 1]) {
                p.push_back({cnt, start});
                cnt = 0;
                --i;
            } else {
                ++cnt;
            }
        }
    }
    p.push_back({cnt, start});
    int ans = 0;
    REP(i, p.size()) {
        int sum = 0;
        if (i >= 1) sum += p[i - 1].first;
        sum += p[i].first;
        if (i <= n - 2) sum += p[i + 1].first;
        chmax(ans, sum);
    }
    output(ans);
}

Submission Info

Submission Time
Task 1 - 電飾 (Illumination)
User noko206
Language C++ (GCC 9.2.1)
Score 100
Code Size 2333 Byte
Status AC
Exec Time 18 ms
Memory 4136 KiB

Compile Error

./Main.cpp: In instantiation of ‘void output(const T&, const Ts& ...) [with T = int; Ts = {}]’:
./Main.cpp:64:15:   required from here
./Main.cpp:26:86: warning: statement has no effect [-Wunused-value]
   26 | template<class T, class... Ts> void output(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
      |                                                                                      ^~~~

Judge Result

Set Name 01 02 03 04
Score / Max Score 10 / 10 10 / 10 20 / 20 60 / 60
Status
AC × 8
AC × 8
AC × 8
AC × 8
Set Name Test Cases
01 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt
02 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt
03 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt
04 04-01.txt, 04-02.txt, 04-03.txt, 04-04.txt, 04-05.txt, 04-06.txt, 04-07.txt, 04-08.txt
Case Name Status Exec Time Memory
01-01.txt AC 12 ms 3564 KiB
01-02.txt AC 3 ms 3584 KiB
01-03.txt AC 2 ms 3564 KiB
01-04.txt AC 2 ms 3568 KiB
01-05.txt AC 2 ms 3596 KiB
01-06.txt AC 3 ms 3596 KiB
01-07.txt AC 3 ms 3592 KiB
01-08.txt AC 2 ms 3580 KiB
02-01.txt AC 3 ms 3664 KiB
02-02.txt AC 3 ms 3624 KiB
02-03.txt AC 2 ms 3596 KiB
02-04.txt AC 2 ms 3632 KiB
02-05.txt AC 2 ms 3516 KiB
02-06.txt AC 2 ms 3524 KiB
02-07.txt AC 3 ms 3652 KiB
02-08.txt AC 2 ms 3568 KiB
03-01.txt AC 3 ms 3512 KiB
03-02.txt AC 2 ms 3656 KiB
03-03.txt AC 2 ms 3540 KiB
03-04.txt AC 2 ms 3544 KiB
03-05.txt AC 4 ms 3580 KiB
03-06.txt AC 3 ms 3600 KiB
03-07.txt AC 3 ms 3476 KiB
03-08.txt AC 3 ms 3472 KiB
04-01.txt AC 6 ms 3656 KiB
04-02.txt AC 7 ms 3596 KiB
04-03.txt AC 13 ms 3956 KiB
04-04.txt AC 14 ms 3636 KiB
04-05.txt AC 12 ms 3620 KiB
04-06.txt AC 13 ms 3600 KiB
04-07.txt AC 13 ms 3696 KiB
04-08.txt AC 18 ms 4136 KiB