CSES - Aalto Competitive Programming 2024 - wk7 - Mon - Results
Submission details
Task:3SUM
Sender:AleksandrPolitov
Submission time:2024-10-21 16:38:44 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#3ACCEPTED0.00 sdetails
#40.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#100.00 sdetails
#11ACCEPTED0.00 sdetails
#120.01 sdetails
#130.00 sdetails
#140.01 sdetails
#150.00 sdetails
#160.01 sdetails
#170.01 sdetails
#18ACCEPTED0.01 sdetails
#190.00 sdetails
#200.01 sdetails
#210.01 sdetails
#220.00 sdetails
#230.00 sdetails

Code

#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define char unsigned char
#define rep(i, a, b) for(int i=a; i< (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back

#define LSOne(S) ((S) & -(S))

using namespace std;
// mt19937 rnd(239);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> int sgn(T x) { return (T(0) < x) - (x < T(0)); }
typedef long double T;
typedef complex<T> pt;
#define X real()
#define Y imag()

template<class T>
istream& operator>> (istream& is, complex<T>& p) {
    T value;
    is >> value;
    p.real(value);
    is >> value;
    p.imag(value);
    return is;
}

typedef long long ll;
typedef long double ld;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif

template<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;}
template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;}

const int INF = 1e9; // 10^9 = 1B is < 2^31-1
const ll LLINF = 4e18; // 4*10^18 is < 2^63-1
const double EPS = 1e-9;
const ll MOD = 1e9+7;

int solve() {
    ll n, x; std::cin >> n >> x;
    vector<pair<ll, ll>> v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> v[i].fi;
        v[i].se=i+1;
    }
    sort(v.begin(), v.end());

    int l=0, r=n-1;
    while(l<r) {
        //std::cout << l << " " << r << ": " << v[l].fi+v[r].fi  << std::endl;
        {
            ll lo=l, hi=r;
            while(lo<hi) {
                ll mid=(lo+hi+1)/2;
                if(v[l].fi+v[r].fi+v[mid].fi==x) {
                    std::cout << v[l].se << " " << v[r].se << " " << v[mid].se << std::endl;
                    return 0;
                } else if(v[l].fi+v[r].fi+v[mid].fi>x) {
                    hi=mid-1;
                } else {
                    lo=mid;
                }
            }
        }
        if(v[l].fi+v[r].fi>=x) r--;
        else l++;
    }

    
    return 0;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1;
    //cin >> TET;
    for (int i = 1; i <= TET; i++) {
        #ifdef ONPC
            cout << "TEST CASE#" << i << endl;
        #endif
        
        if (solve()) {
            break;
        }

        #ifdef ONPC
            cout << "__________________________" << endl;
        #endif
    }
    #ifdef ONPC
        cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
}

Test details

Test 1

Verdict:

input
1 3
1

correct output
IMPOSSIBLE

user output
(empty)

Test 2

Verdict:

input
3 5
1 3 2

correct output
IMPOSSIBLE

user output
(empty)

Test 3

Verdict: ACCEPTED

input
3 6
1 3 2

correct output
1 3 2

user output
1 2 3

Test 4

Verdict:

input
3 7
3 2 1

correct output
IMPOSSIBLE

user output
3 1 1

Test 5

Verdict: ACCEPTED

input
7 3
2 1 1 2 2 1 1

correct output
2 3 7

user output
2 7 6

Test 6

Verdict: ACCEPTED

input
7 4
1 1 2 2 1 2 1

correct output
1 2 6

user output
1 6 7

Test 7

Verdict: ACCEPTED

input
7 5
1 2 1 2 2 1 1

correct output
1 2 5

user output
1 5 4

Test 8

Verdict: ACCEPTED

input
7 6
2 1 1 1 1 2 2

correct output
1 6 7

user output
1 7 6

Test 9

Verdict: ACCEPTED

input
5000 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1 2 5000

user output
1 5000 2501

Test 10

Verdict:

input
5000 4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
IMPOSSIBLE

user output
(empty)

Test 11

Verdict: ACCEPTED

input
5000 6
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
714 3518 4240

user output
714 4240 3518

Test 12

Verdict:

input
5000 919900245
663612758 9075403 585385629 98...

correct output
2787 465 2266

user output
(empty)

Test 13

Verdict:

input
5000 999989608
12983 25966 38949 51932 64915 ...

correct output
IMPOSSIBLE

user output
(empty)

Test 14

Verdict:

input
5000 1000000000
65536 131072 196608 262144 327...

correct output
IMPOSSIBLE

user output
(empty)

Test 15

Verdict:

input
5000 642700000
6427 12854 19281 25708 32135 3...

correct output
IMPOSSIBLE

user output
(empty)

Test 16

Verdict:

input
5000 919900246
663612758 9075403 585385629 98...

correct output
193 1698 4019

user output
(empty)

Test 17

Verdict:

input
5000 919900247
663612758 9075403 585385629 98...

correct output
4258 470 1911

user output
(empty)

Test 18

Verdict: ACCEPTED

input
5000 6
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 ...

correct output
4998 4999 5000

user output
4998 5000 4999

Test 19

Verdict:

input
5000 919900247
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
IMPOSSIBLE

user output
(empty)

Test 20

Verdict:

input
4999 919900245
9075403 585385629 987230075 83...

correct output
2786 464 2265

user output
(empty)

Test 21

Verdict:

input
5000 1000000000
261323261 25262018 237798562 3...

correct output
IMPOSSIBLE

user output
(empty)

Test 22

Verdict:

input
5000 76305003
1 5088 10175 15262 20349 25436...

correct output
IMPOSSIBLE

user output
(empty)

Test 23

Verdict:

input
2 6
2 2

correct output
IMPOSSIBLE

user output
1 2 2