Submission #39675868


Source Code Expand

#include "bits/stdc++.h"
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ll long long

// #define MOD 998244353LL
#define MOD 1000000007LL
// using mint = modint998244353;
// using mint = modint1000000007;

#define chmax(a, b) \
    if ((a) < (b))  \
        a = (b);
#define chmin(a, b) \
    if ((a) > (b))  \
        a = (b);
#define doublecout(a) cout << setprecision(16) << a << endl;
using vi = vector<ll>;    // intの1次元の型に vi という別名をつける
using vvi = vector<vi>;   // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX = 9223372036854775807LL;
const ll llMIN = -9223372036854775808LL;

#ifdef LOCAL
#define dbg(x_) cerr << "?" << __LINE__ << ":" << #x_ << ":\t" << x_ << endl;
#define print1(a0_) cerr << "?" << __LINE__ << ":" << #a0_ << "=" << a0_ << endl;
#define print2(a0_, a1_) cerr << "?" << __LINE__ << ":" << #a0_ << "=" << a0_ << "," << #a1_ << "=" << a1_ << endl;
#define print3(a0_, a1_, a2_) cerr << "?" << __LINE__ << ":" << #a0_ << "=" << a0_ << "," << #a1_ << "=" << a1_ << "," << #a2_ << "=" << a2_ << endl;
#define print4(a0_, a1_, a2_, a3_) cerr << "?" << __LINE__ << ":" << #a0_ << "=" << a0_ << "," << #a1_ << "=" << a1_ << "," << #a2_ << "=" << a2_ << "," << #a3_ << "=" << a3_ << endl;
#define print5(a0_, a1_, a2_, a3_, a4_) cerr << "?" << __LINE__ << ":" << #a0_ << "=" << a0_ << "," << #a1_ << "=" << a1_ << "," << #a2_ << "=" << a2_ << "," << #a3_ << "=" << a3_ << "," << #a4_ << "=" << a4_ << endl;
#else
#define dbg(...)
#define print1(...)
#define print2(...)
#define print3(...)
#define print4(...)
#define print5(...)
#endif

template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p)
{
    return s << "(" << p.first << "," << p.second << ")";
}

// vector
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &v)
{
    int len = v.size();
    for (int i = 0; i < len; ++i)
    {
        s << v[i];
        if (i < len - 1)
            s << "\t";
    }
    return s;
}

// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv)
{
    s << endl;
    int len = vv.size();
    for (int i = 0; i < len; ++i)
        s << vv[i] << endl;
    return s;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &mp)
{
    int len = mp.size();
    for (auto t : mp)
        s << t << " ";
    return s;
}

void No()
{
    cout << "-1" << endl;
    exit(0);
}

ll n, k, x, y;

int main()
{
    cin >> n;
    vi a(n), b(n);
    REP(i, n)cin >> a[i];

    vvi ldata(n, vi(6)); // +の最大、+の最小,1,-1,-の最大,-の最小
    vvi rdata(n, vi(6)); // +の最大、+の最小,1,-1,-の最大,-の最小

    //ldata[0][0] = 1;
    //ldata[0][1] = 9999999;
    // lから
    for (ll i = 1; i < n; i++)
    {
        // ldata[i+1]
        if (a[i - 1] > 1)
        {
            ldata[i][0] = max(ldata[i - 1][0], a[i - 1]);
            if (ldata[i - 1][1]==0)
            {
                ldata[i][1] = a[i - 1];
            }
            else
            {
                ldata[i][1] = min(ldata[i - 1][1], a[i - 1]);
            }
        }
        else
        {
            ldata[i][0] = ldata[i - 1][0];
            ldata[i][1] = ldata[i - 1][1];
        }
        if (a[i - 1] < -1)
        {
            if (ldata[i - 1][4]==0)
            {
                ldata[i][4] = a[i - 1];
            }
            else
            {
                ldata[i][4] = max(ldata[i - 1][4], a[i - 1]);
            }

            ldata[i][5] = min(ldata[i - 1][5], a[i - 1]);
        }
        else
        {
            ldata[i][4] = ldata[i - 1][4];
            ldata[i][5] = ldata[i - 1][5];
        }

        if (a[i - 1] == 1)
        {
            ldata[i][2] = 1;
        }
        else
        {
            ldata[i][2] = ldata[i - 1][2];
        }

        if (a[i - 1] == -1)
        {
            ldata[i][3] = -1;
        }
        else
        {
            ldata[i][3] = ldata[i - 1][3];
        }
    }

    //r
    for (ll i = n-2; i >=0; i--)
    {
        // rdata[i+1]
        if (a[i + 1] > 1)
        {
            rdata[i][0] = max(rdata[i + 1][0], a[i + 1]);
            if (rdata[i + 1][1]==0)
            {
                rdata[i][1] = a[i + 1];
            }
            else
            {
                rdata[i][1] = min(rdata[i + 1][1], a[i + 1]);
            }
        }
        else
        {
            rdata[i][0] = rdata[i + 1][0];
            rdata[i][1] = rdata[i + 1][1];
        }
        if (a[i + 1] < -1)
        {
            if (rdata[i + 1][4]==0)
            {
                rdata[i][4] = a[i + 1];
            }
            else
            {
                rdata[i][4] = max(rdata[i + 1][4], a[i + 1]);
            }

            rdata[i][5] = min(rdata[i + 1][5], a[i + 1]);
        }
        else
        {
            rdata[i][4] = rdata[i + 1][4];
            rdata[i][5] = rdata[i + 1][5];
        }

        if (a[i + 1] == 1)
        {
            rdata[i][2] = 1;
        }
        else
        {
            rdata[i][2] = rdata[i + 1][2];
        }

        if (a[i + 1] == -1)
        {
            rdata[i][3] = -1;
        }
        else
        {
            rdata[i][3] = rdata[i + 1][3];
        }
    }



    double dminans = 9999999999999999999999999999999999999999.9;
    double dmaxans = -9999999999999999999999999999999999999999.9;

    for(ll i=1;i<n-1;i++){
        double aj=a[i];
        for(ll k=0;k<6;k++){
            if (ldata[i][k]==0)
                continue;
            for (ll j = 0; j < 6; j++)
            {
                if (rdata[i][j] == 0)
                    continue;
                double ld = ldata[i][k];
                double rd = rdata[i][j];
                double tmp = (aj + ld + rd) / (ld * rd * aj);
                //cout << ldata[i][k] << " " << aj << " " << rdata[i][j]<<endl;
                dminans = min(dminans, tmp);
                dmaxans = max(dmaxans, tmp);
            }
        }
    }

    doublecout(dminans);
    doublecout(dmaxans);
    return 0;
}

Submission Info

Submission Time
Task B - Sum-Product Ratio
User toropippi
Language C++ (GCC 9.2.1)
Score 500
Code Size 6489 Byte
Status AC
Exec Time 106 ms
Memory 40716 KiB

Compile Error

./Main.cpp:24:19: warning: integer constant is so large that it is unsigned
   24 | const ll llMIN = -9223372036854775808LL;
      |                   ^~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 48
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 02_small_11.txt, 02_small_12.txt, 02_small_13.txt, 02_small_14.txt, 02_small_15.txt, 02_small_16.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 05_almost_negative_01.txt, 05_almost_negative_02.txt, 05_almost_negative_03.txt, 05_almost_negative_04.txt, 05_almost_negative_05.txt, 05_almost_negative_06.txt, 05_almost_negative_07.txt, 05_almost_negative_08.txt, 06_almost_positive_01.txt, 06_almost_positive_02.txt, 06_almost_positive_03.txt, 06_almost_positive_04.txt, 06_almost_positive_05.txt, 06_almost_positive_06.txt, 06_almost_positive_07.txt, 06_almost_positive_08.txt, 07_many_equal_01.txt, 07_many_equal_02.txt, 07_many_equal_03.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 6 ms 3600 KiB
01_sample_02.txt AC 2 ms 3680 KiB
01_sample_03.txt AC 2 ms 3632 KiB
02_small_01.txt AC 2 ms 3640 KiB
02_small_02.txt AC 2 ms 3664 KiB
02_small_03.txt AC 2 ms 3596 KiB
02_small_04.txt AC 2 ms 3660 KiB
02_small_05.txt AC 2 ms 3640 KiB
02_small_06.txt AC 2 ms 3660 KiB
02_small_07.txt AC 2 ms 3644 KiB
02_small_08.txt AC 4 ms 3648 KiB
02_small_09.txt AC 2 ms 3600 KiB
02_small_10.txt AC 2 ms 3644 KiB
02_small_11.txt AC 2 ms 3676 KiB
02_small_12.txt AC 2 ms 3672 KiB
02_small_13.txt AC 2 ms 3616 KiB
02_small_14.txt AC 2 ms 3596 KiB
02_small_15.txt AC 2 ms 3664 KiB
02_small_16.txt AC 2 ms 3676 KiB
03_rand_1_01.txt AC 106 ms 40652 KiB
03_rand_1_02.txt AC 104 ms 40656 KiB
03_rand_1_03.txt AC 102 ms 40660 KiB
03_rand_1_04.txt AC 104 ms 40500 KiB
03_rand_1_05.txt AC 100 ms 40660 KiB
04_rand_2_01.txt AC 103 ms 40600 KiB
04_rand_2_02.txt AC 102 ms 40580 KiB
04_rand_2_03.txt AC 101 ms 40560 KiB
04_rand_2_04.txt AC 102 ms 40584 KiB
04_rand_2_05.txt AC 101 ms 40656 KiB
05_almost_negative_01.txt AC 100 ms 40596 KiB
05_almost_negative_02.txt AC 99 ms 40600 KiB
05_almost_negative_03.txt AC 105 ms 40636 KiB
05_almost_negative_04.txt AC 101 ms 40580 KiB
05_almost_negative_05.txt AC 96 ms 40716 KiB
05_almost_negative_06.txt AC 97 ms 40504 KiB
05_almost_negative_07.txt AC 102 ms 40560 KiB
05_almost_negative_08.txt AC 100 ms 40660 KiB
06_almost_positive_01.txt AC 91 ms 40660 KiB
06_almost_positive_02.txt AC 94 ms 40512 KiB
06_almost_positive_03.txt AC 95 ms 40596 KiB
06_almost_positive_04.txt AC 97 ms 40560 KiB
06_almost_positive_05.txt AC 91 ms 40652 KiB
06_almost_positive_06.txt AC 93 ms 40660 KiB
06_almost_positive_07.txt AC 93 ms 40516 KiB
06_almost_positive_08.txt AC 96 ms 40564 KiB
07_many_equal_01.txt AC 94 ms 40500 KiB
07_many_equal_02.txt AC 98 ms 40580 KiB
07_many_equal_03.txt AC 94 ms 40596 KiB