| Task: | 3SUM |
| Sender: | rikachu |
| Submission time: | 2025-10-20 17:02:00 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.01 s | details |
| #3 | WRONG ANSWER | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | WRONG ANSWER | 0.00 s | details |
| #6 | WRONG ANSWER | 0.00 s | details |
| #7 | ACCEPTED | 0.00 s | details |
| #8 | WRONG ANSWER | 0.00 s | details |
| #9 | ACCEPTED | 0.01 s | details |
| #10 | ACCEPTED | 0.04 s | details |
| #11 | WRONG ANSWER | 0.04 s | details |
| #12 | RUNTIME ERROR | 0.00 s | details |
| #13 | RUNTIME ERROR | 0.00 s | details |
| #14 | RUNTIME ERROR | 0.00 s | details |
| #15 | RUNTIME ERROR | 0.00 s | details |
| #16 | RUNTIME ERROR | 0.00 s | details |
| #17 | RUNTIME ERROR | 0.01 s | details |
| #18 | ACCEPTED | 0.01 s | details |
| #19 | ACCEPTED | 0.04 s | details |
| #20 | RUNTIME ERROR | 0.00 s | details |
| #21 | RUNTIME ERROR | 0.00 s | details |
| #22 | RUNTIME ERROR | 0.00 s | details |
| #23 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
// === Debug macro starts here ===
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) \
{ \
++recur_depth; \
auto x_ = x; \
--recur_depth; \
cerr << string(recur_depth, '\t') << "\e[91m" << __func__ << ":" \
<< __LINE__ << "\t" << #x << " = " << x_ << "\e[39m" << endl; \
}
#else
#define dbg(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<(
Ostream& os, const Cont& v) {
os << "[";
for (auto& x : v) {
os << x << ", ";
}
return os << "]";
}
// === Debug macro ends here ===
// bit-twiddling
#define bit(x, i) ((x) & (1 << (i))) // select the bit of position i of x
#define setbit(x, i) ((x) | (1 << (i))) // set the bit of position i of x
#define unsetbit(x, i) ((x) & ~(1 << (i))) // etc
#define togglebit(x, i) ((x) ^ (1 << (i)))
#define lowbit(x) ((x) & -(x)) // get the lowest bit of x
// iteration
#define all(x) (x).begin(), (x).end()
// maps, pairs
#define mp make_pair
#define fi first
#define se second
// vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
// directions
const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
// print pair, vector
template <typename Ostream, typename... Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p) {
return os << "{" << p.first << ", " << p.second << "}";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
for (const T& v : t) {
cout << v << " ";
}
return s;
}
// types
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using us = unsigned short;
const int INF = 1001001001;
const int MAXN = 10000;
const char br = '\n';
int nxt() {
int x;
cin >> x;
return x;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt", "r", stdin);
int n = nxt();
int x = nxt();
vector<ii> arr(n + 1);
vb table(5001);
for (int i = 0; i < n; ++i) {
int a = nxt();
table[a] = true;
arr[i] = mp(a, i + 1);
}
sort(all(arr));
for (int i = 0; i < n - 2; ++i) {
auto a = arr[i];
int start = i + 1;
int end = n - 1;
while (start < end) {
auto b = arr[start];
auto c = arr[end];
if (a.fi + b.fi + c.fi == x) {
vi ans;
ans.pb(a.se);
ans.pb(b.se);
ans.pb(c.se);
sort(all(ans));
cout << ans << br;
return 0;
} else if (a.fi + b.fi + c.fi > x) {
end--;
} else {
start++;
}
}
}
cout << "IMPOSSIBLE" << br;
return 0;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 1 3 1 |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 3 5 1 3 2 |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 3 6 1 3 2 |
| correct output |
|---|
| 1 3 2 |
| user output |
|---|
| IMPOSSIBLE |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 3 7 3 2 1 |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 7 3 2 1 1 2 2 1 1 |
| correct output |
|---|
| 2 3 7 |
| user output |
|---|
| 0 2 4 |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 7 4 1 1 2 2 1 2 1 |
| correct output |
|---|
| 1 2 6 |
| user output |
|---|
| 0 3 4 |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 7 5 1 2 1 2 2 1 1 |
| correct output |
|---|
| 1 2 5 |
| user output |
|---|
| 1 2 4 |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 7 6 2 1 1 1 1 2 2 |
| correct output |
|---|
| 1 6 7 |
| user output |
|---|
| IMPOSSIBLE |
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 2 4999 |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 5000 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 11
Verdict: WRONG ANSWER
| 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 |
|---|
| IMPOSSIBLE |
Test 12
Verdict: RUNTIME ERROR
| input |
|---|
| 5000 919900245 663612758 9075403 585385629 98... |
| correct output |
|---|
| 2787 465 2266 |
| user output |
|---|
| (empty) |
Test 13
Verdict: RUNTIME ERROR
| input |
|---|
| 5000 999989608 12983 25966 38949 51932 64915 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| (empty) |
Test 14
Verdict: RUNTIME ERROR
| input |
|---|
| 5000 1000000000 65536 131072 196608 262144 327... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| (empty) |
Test 15
Verdict: RUNTIME ERROR
| input |
|---|
| 5000 642700000 6427 12854 19281 25708 32135 3... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| (empty) |
Test 16
Verdict: RUNTIME ERROR
| input |
|---|
| 5000 919900246 663612758 9075403 585385629 98... |
| correct output |
|---|
| 193 1698 4019 |
| user output |
|---|
| (empty) |
Test 17
Verdict: RUNTIME ERROR
| 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 4999 5000 |
Test 19
Verdict: ACCEPTED
| input |
|---|
| 5000 919900247 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
Test 20
Verdict: RUNTIME ERROR
| input |
|---|
| 4999 919900245 9075403 585385629 987230075 83... |
| correct output |
|---|
| 2786 464 2265 |
| user output |
|---|
| (empty) |
Test 21
Verdict: RUNTIME ERROR
| input |
|---|
| 5000 1000000000 261323261 25262018 237798562 3... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| (empty) |
Test 22
Verdict: RUNTIME ERROR
| input |
|---|
| 5000 76305003 1 5088 10175 15262 20349 25436... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| (empty) |
Test 23
Verdict: ACCEPTED
| input |
|---|
| 2 6 2 2 |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE |
