結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー fastmathfastmath
提出日時 2021-01-22 23:20:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 5,018 bytes
コンパイル時間 2,462 ms
コンパイル使用メモリ 218,296 KB
実行使用メモリ 57,976 KB
最終ジャッジ日時 2023-08-27 22:33:15
合計ジャッジ時間 22,423 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 26 ms
6,260 KB
testcase_19 AC 10 ms
4,592 KB
testcase_20 AC 25 ms
5,916 KB
testcase_21 AC 11 ms
5,080 KB
testcase_22 AC 15 ms
4,944 KB
testcase_23 AC 23 ms
5,768 KB
testcase_24 AC 22 ms
5,772 KB
testcase_25 AC 23 ms
5,592 KB
testcase_26 AC 27 ms
6,132 KB
testcase_27 AC 15 ms
5,040 KB
testcase_28 AC 204 ms
26,532 KB
testcase_29 AC 165 ms
19,108 KB
testcase_30 AC 150 ms
17,668 KB
testcase_31 AC 202 ms
28,696 KB
testcase_32 AC 223 ms
33,340 KB
testcase_33 AC 147 ms
17,688 KB
testcase_34 AC 227 ms
30,612 KB
testcase_35 AC 252 ms
30,148 KB
testcase_36 AC 397 ms
44,204 KB
testcase_37 AC 96 ms
14,892 KB
testcase_38 AC 194 ms
21,892 KB
testcase_39 AC 119 ms
16,488 KB
testcase_40 AC 150 ms
19,204 KB
testcase_41 AC 226 ms
25,276 KB
testcase_42 AC 363 ms
39,272 KB
testcase_43 AC 214 ms
26,952 KB
testcase_44 AC 276 ms
32,224 KB
testcase_45 AC 210 ms
23,972 KB
testcase_46 AC 228 ms
31,932 KB
testcase_47 AC 131 ms
16,936 KB
testcase_48 AC 388 ms
54,036 KB
testcase_49 AC 333 ms
54,748 KB
testcase_50 AC 406 ms
54,912 KB
testcase_51 AC 373 ms
56,592 KB
testcase_52 AC 326 ms
55,876 KB
testcase_53 AC 515 ms
54,172 KB
testcase_54 AC 510 ms
56,472 KB
testcase_55 AC 547 ms
55,480 KB
testcase_56 AC 508 ms
55,056 KB
testcase_57 AC 384 ms
56,288 KB
testcase_58 AC 235 ms
57,328 KB
testcase_59 AC 233 ms
53,816 KB
testcase_60 AC 243 ms
55,816 KB
testcase_61 AC 242 ms
57,976 KB
testcase_62 AC 244 ms
57,020 KB
testcase_63 AC 204 ms
54,192 KB
testcase_64 AC 200 ms
54,292 KB
testcase_65 AC 204 ms
54,580 KB
testcase_66 AC 204 ms
53,872 KB
testcase_67 AC 200 ms
54,012 KB
testcase_68 AC 2 ms
4,380 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 2 ms
4,376 KB
testcase_71 AC 1 ms
4,376 KB
testcase_72 AC 2 ms
4,376 KB
testcase_73 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define x first
#define y second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define trav(a, x) for (auto& a : x)
using vi = vector<int>;
template <typename T>
std::ostream& operator <<(std::ostream& output, const pair <T, T> & data)
{
    output << "(" << data.x << "," << data.y << ")";
    return output;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const std::vector<T>& data)
{
    for (const T& x : data)
        output << x << " ";
    return output;
}
ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down 
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>; 
tcT> void re(V<T>& x) { 
    trav(a, x)
        cin >> a;
}
tcT> bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0; 
} // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; 
}
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    vi sz(4);
    FOR (i, 4)
        cin >> sz[i];
    int k;
    cin >> k;
    V <vi> a(4);
    FOR (i, 4) {
        a[i].resize(sz[i]);
        FOR (j, sz[i])
            cin >> a[i][j];
    }   

    V <vi> l, r;
    vi lv, rv;
    trav (i, a[0])
        trav (j, a[1]) {
            l.app({i * j, i, j});
            lv.app(i * j);
        }

    sort(all(l));
    sort(all(lv));
    vi lv_rev = lv;
    reverse(all(lv_rev));
    trav (i, a[2])
        trav (j, a[3]) {
            r.app({i * j, i, j});
            rv.app(i * j);
        }
    sort(all(r));
    sort(all(rv));
        
    const int INF = 2e18;
    auto cnt = [&] (int x) {
        //prod <= x
        int ans = 0;

        trav (a, lv) {
            if (a == 0 && x >= 0) {
                ans += rv.size();
            }   
        }   

        if (x >= 0) {
        int ptr = 0;
        trav (a, lv_rev) {
            if (a < 0) {
                while (ptr < rv.size() && a * rv[ptr] > x) {
                    ptr++;
                }   
                ans += (int)rv.size() - ptr;
            }   
        }
        }
        else {
        int ptr = 0;
        trav (a, lv) {
            if (a < 0) {
                while (ptr < rv.size() && a * rv[ptr] > x) {
                    ptr++;
                }   
                ans += (int)rv.size() - ptr;
            }   
        }
        }
        
        if (x >= 0) {
        int ptr = 0;
        trav (a, lv_rev) {
            if (a > 0) {
                while (ptr < rv.size() && a * rv[ptr] <= x) {
                    ptr++;
                }   
                ans += ptr;
            }   
        }   
        }
        else {
        int ptr = 0;
        trav (a, lv) {
            if (a > 0) {
                while (ptr < rv.size() && a * rv[ptr] <= x) {
                    ptr++;
                }   
                ans += ptr;
            }   
        }   
        }

        /*
        int ans1 = 0;
        trav (v, l) {
            int a = v[0];
            if (a == 0) {
                if (0 <= x)
                    ans1 += r.size();
            }   
            else if (a < 0) {
                //a * b <= x
                //b >= x/a
                ans1 += get_right(r, div_up(x, a));
            }   
            else {
                //b <= x/a
                ans1 += get_left(r, div_down(x, a));
            }   
        }
        assert(ans == ans1);
        */

        return ans;
    };  

    int ans;
    {

    assert(cnt(INF) == sz[0] * sz[1] * sz[2] * sz[3]);
    assert(cnt(-INF) == 0);

    int l = -INF, r = INF; // l < ans
    while (l < r - 1) {
        int m = (l + r) / 2;
        if (cnt(m) < k)
            l = m;
        else
            r = m;
    }   
    assert(l != -INF);
    assert(r != INF);
    ans = r;
    cout << r << endl;
    }

    #ifdef HOME
    debug(Time);
    #endif

    trav (v, l) {
        int a = v[0];
        if (a == 0) {
            if (ans == 0) {
                auto vv = r[0];
                cout << v[1] << ' ' << v[2] << ' ' << vv[1] << ' ' << vv[2] << endl;
                exit(0);                
            }
        }   
        else if (ans % a == 0) {
            int b = ans/a;
            vi key = {b, -INF, -INF};
            auto t = lower_bound(all(r), key);
            if (t != r.end() && (*t)[0] == b) {
                auto vv = *t;
                cout << v[1] << ' ' << v[2] << ' ' << vv[1] << ' ' << vv[2] << endl;
                exit(0);
            }   
        }   
    }       
    cout << "LMAO" << endl;
}
0