CSES - Aalto Competitive Programming 2024 - wk10 - Wed - Results
Submission details
Task:Fishers
Sender:aalto2024k_003
Submission time:2024-11-13 18:15:37 +0200
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#28ACCEPTED0.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.00 sdetails
#32ACCEPTED0.00 sdetails
#33ACCEPTED0.00 sdetails
#34ACCEPTED0.00 sdetails
#35ACCEPTED0.00 sdetails
#36ACCEPTED0.00 sdetails
#37ACCEPTED0.00 sdetails
#38ACCEPTED0.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.00 sdetails
#42ACCEPTED0.00 sdetails
#43ACCEPTED0.00 sdetails
#44ACCEPTED0.00 sdetails
#45ACCEPTED0.00 sdetails
#46ACCEPTED0.00 sdetails
#47ACCEPTED0.00 sdetails
#48ACCEPTED0.00 sdetails
#49ACCEPTED0.00 sdetails
#50ACCEPTED0.00 sdetails
#51ACCEPTED0.00 sdetails
#52ACCEPTED0.00 sdetails
#53ACCEPTED0.00 sdetails
#54ACCEPTED0.00 sdetails
#55ACCEPTED0.00 sdetails
#56ACCEPTED0.00 sdetails
#57ACCEPTED0.00 sdetails
#58ACCEPTED0.00 sdetails
#59ACCEPTED0.00 sdetails
#60ACCEPTED0.00 sdetails
#61ACCEPTED0.03 sdetails
#62ACCEPTED0.03 sdetails
#63ACCEPTED0.03 sdetails
#64ACCEPTED0.03 sdetails
#65ACCEPTED0.03 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:60:20: warning: statement has no effect [-Wunused-value]
   60 | #define debug(...) 42
      |                    ^~
input/code.cpp:94:9: note: in expansion of macro 'debug'
   94 |         debug(i, f[i]);
      |         ^~~~~
input/code.cpp:60:20: warning: statement has no effect [-Wunused-value]
   60 | #define debug(...) 42
      |                    ^~
input/code.cpp:104:9: note: in expansion of macro 'debug'
  104 |         debug(from, lim);
      |         ^~~~~
input/code.cpp:60:20: warning: statement has no effect [-Wunused-value]
   60 | #define debug(...) 42
      |                    ^~
input/code.cpp:110:13: note: in expansion of macro 'debug'
  110 |             debug(who, from, to, lim);
      |             ^~~~~

Code

#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define int long long
#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()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}
 
string to_string(const char* s) {
    return to_string((string) s);
}
 
string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
 
void debug_out() {
    cerr << endl;
}
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;
const int INF = 1e9;

int n, f[2 * N];
int pos[N];
int line[N];
bool vis[N];

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit); // RTE if input wrong datatype

    cin >> n;
    for (int i = 0; i < 2 * n; i++) {
        cin >> f[i];
        if (f[i] > 0) {
            if (vis[f[i]]) { // swap so that the fisher always sit first
                pos[f[i]] = line[f[i]];
                line[f[i]] = i;
                f[pos[f[i]]] = -f[pos[f[i]]];
                f[i] = -f[i];
            } else {
                pos[f[i]] = i;   
            }
        } else {
            line[-f[i]] = i;
            vis[-f[i]] = i;
        }
    }

    for (int i = 0; i < 2 * n; i++) {
        debug(i, f[i]);
    }

    int lim = INF;
    for (int from = 0; from < 2 * n; from++) {
        if (from == lim) {
            int who = -f[from];
            int to = pos[who];
            lim = to + 2*n;
        }
        debug(from, lim);
        if (f[from] > 0) {
            int who = f[from];
            int to = line[who];
            if (to < from) to += 2 * n;
            
            debug(who, from, to, lim);

            if (to > lim) {
                cout << "Yes";
                return 0;
            }
            lim = min(lim, to);
        }
    }
    cout << "No";
}

Test details

Test 1

Verdict: ACCEPTED

input
1
-1 1 

correct output
No

user output
No

Test 2

Verdict: ACCEPTED

input
2
1 -2 -1 2 

correct output
Yes

user output
Yes

Test 3

Verdict: ACCEPTED

input
2
-2 2 1 -1 

correct output
No

user output
No

Test 4

Verdict: ACCEPTED

input
3
-2 -3 -1 1 3 2 

correct output
No

user output
No

Test 5

Verdict: ACCEPTED

input
3
-2 -1 -3 3 1 2 

correct output
No

user output
No

Test 6

Verdict: ACCEPTED

input
3
2 3 -2 -1 1 -3 

correct output
Yes

user output
Yes

Test 7

Verdict: ACCEPTED

input
4
3 2 1 -1 -2 -3 4 -4 

correct output
No

user output
No

Test 8

Verdict: ACCEPTED

input
4
-3 1 -1 3 -2 -4 4 2 

correct output
No

user output
No

Test 9

Verdict: ACCEPTED

input
4
3 -3 2 -4 1 -1 4 -2 

correct output
No

user output
No

Test 10

Verdict: ACCEPTED

input
4
-1 1 -2 2 3 4 -4 -3 

correct output
No

user output
No

Test 11

Verdict: ACCEPTED

input
5
4 3 5 -2 -1 1 2 -5 -3 -4 

correct output
No

user output
No

Test 12

Verdict: ACCEPTED

input
5
1 2 -2 -1 4 3 -5 5 -3 -4 

correct output
No

user output
No

Test 13

Verdict: ACCEPTED

input
5
2 -5 5 1 3 4 -4 -3 -1 -2 

correct output
No

user output
No

Test 14

Verdict: ACCEPTED

input
5
2 -2 1 -5 -4 4 5 -1 -3 3 

correct output
No

user output
No

Test 15

Verdict: ACCEPTED

input
5
-1 -4 5 3 2 -5 1 4 -3 -2 

correct output
Yes

user output
Yes

Test 16

Verdict: ACCEPTED

input
5
1 2 -3 -5 -4 4 5 3 -2 -1 

correct output
No

user output
No

Test 17

Verdict: ACCEPTED

input
5
4 -1 -5 -4 2 5 -3 1 -2 3 

correct output
Yes

user output
Yes

Test 18

Verdict: ACCEPTED

input
5
-2 4 -4 2 3 1 5 -5 -1 -3 

correct output
No

user output
No

Test 19

Verdict: ACCEPTED

input
5
-4 -5 -1 3 1 -2 2 -3 4 5 

correct output
Yes

user output
Yes

Test 20

Verdict: ACCEPTED

input
5
-5 4 1 -1 -4 2 3 -3 -2 5 

correct output
No

user output
No

Test 21

Verdict: ACCEPTED

input
10
1 -7 7 -1 -2 -5 5 2 -10 4 -9 9...

correct output
No

user output
No

Test 22

Verdict: ACCEPTED

input
10
5 -5 -6 -7 10 9 1 -1 -9 -10 8 ...

correct output
No

user output
No

Test 23

Verdict: ACCEPTED

input
10
-9 1 3 2 -2 5 -5 6 8 7 -7 -8 -...

correct output
No

user output
No

Test 24

Verdict: ACCEPTED

input
10
1 2 -2 -1 -3 4 -4 8 -8 5 -5 -7...

correct output
No

user output
No

Test 25

Verdict: ACCEPTED

input
10
6 3 5 -2 2 -4 10 -6 9 -1 7 8 -...

correct output
Yes

user output
Yes

Test 26

Verdict: ACCEPTED

input
10
6 -9 7 -7 1 -1 9 -6 -3 4 2 -10...

correct output
No

user output
No

Test 27

Verdict: ACCEPTED

input
10
-3 6 8 -9 -1 4 -7 -6 -4 2 5 1 ...

correct output
Yes

user output
Yes

Test 28

Verdict: ACCEPTED

input
10
-4 4 -7 2 -1 10 -3 9 -9 8 -5 -...

correct output
No

user output
No

Test 29

Verdict: ACCEPTED

input
10
-2 -6 7 -1 -8 -5 6 1 4 -4 5 2 ...

correct output
Yes

user output
Yes

Test 30

Verdict: ACCEPTED

input
10
8 -8 -7 -5 -3 10 6 -2 1 -1 2 -...

correct output
No

user output
No

Test 31

Verdict: ACCEPTED

input
100
-14 14 -65 -19 100 44 -73 56 -...

correct output
No

user output
No

Test 32

Verdict: ACCEPTED

input
100
-96 29 -90 80 -6 20 43 39 76 -...

correct output
No

user output
No

Test 33

Verdict: ACCEPTED

input
100
79 -86 -28 40 -5 -11 13 69 -2 ...

correct output
No

user output
No

Test 34

Verdict: ACCEPTED

input
100
74 -80 51 39 -39 -51 80 -74 26...

correct output
No

user output
No

Test 35

Verdict: ACCEPTED

input
100
-53 -48 27 -91 73 38 -80 -12 5...

correct output
Yes

user output
Yes

Test 36

Verdict: ACCEPTED

input
100
82 75 -18 36 59 93 33 74 -16 -...

correct output
No

user output
No

Test 37

Verdict: ACCEPTED

input
100
-100 72 -43 63 95 -37 -48 23 3...

correct output
Yes

user output
Yes

Test 38

Verdict: ACCEPTED

input
100
-74 -89 88 23 -66 16 -21 99 -5...

correct output
No

user output
No

Test 39

Verdict: ACCEPTED

input
100
-78 36 -4 -7 -54 85 10 -61 22 ...

correct output
Yes

user output
Yes

Test 40

Verdict: ACCEPTED

input
100
58 46 -79 14 -11 38 5 39 66 -8...

correct output
No

user output
No

Test 41

Verdict: ACCEPTED

input
200
-133 -37 78 101 -124 26 -200 6...

correct output
No

user output
No

Test 42

Verdict: ACCEPTED

input
200
80 -151 138 -132 -186 145 60 -...

correct output
No

user output
No

Test 43

Verdict: ACCEPTED

input
200
24 157 -185 185 -157 -24 62 -1...

correct output
No

user output
No

Test 44

Verdict: ACCEPTED

input
200
17 84 -43 54 -140 193 -193 140...

correct output
No

user output
No

Test 45

Verdict: ACCEPTED

input
200
62 -196 90 -173 -143 -58 32 -1...

correct output
Yes

user output
Yes

Test 46

Verdict: ACCEPTED

input
200
32 117 -59 80 79 29 92 -78 -94...

correct output
No

user output
No

Test 47

Verdict: ACCEPTED

input
200
-31 -111 144 -198 -49 149 -35 ...

correct output
Yes

user output
Yes

Test 48

Verdict: ACCEPTED

input
200
-148 -131 86 -140 176 -41 -200...

correct output
No

user output
No

Test 49

Verdict: ACCEPTED

input
200
-52 187 95 133 143 -123 -88 -1...

correct output
Yes

user output
Yes

Test 50

Verdict: ACCEPTED

input
200
-101 -182 82 -96 187 114 -129 ...

correct output
No

user output
No

Test 51

Verdict: ACCEPTED

input
1000
-117 815 548 -910 710 -273 -94...

correct output
No

user output
No

Test 52

Verdict: ACCEPTED

input
1000
586 754 -867 772 941 456 -456 ...

correct output
No

user output
No

Test 53

Verdict: ACCEPTED

input
1000
247 -998 -430 897 395 134 993 ...

correct output
No

user output
No

Test 54

Verdict: ACCEPTED

input
1000
-145 981 -405 444 881 -428 640...

correct output
No

user output
No

Test 55

Verdict: ACCEPTED

input
1000
637 313 687 -543 -78 -785 628 ...

correct output
Yes

user output
Yes

Test 56

Verdict: ACCEPTED

input
1000
-616 377 749 -717 -582 436 33 ...

correct output
No

user output
No

Test 57

Verdict: ACCEPTED

input
1000
534 -329 -984 -689 -411 275 -7...

correct output
Yes

user output
Yes

Test 58

Verdict: ACCEPTED

input
1000
-231 -855 815 805 -665 354 497...

correct output
No

user output
No

Test 59

Verdict: ACCEPTED

input
1000
-25 824 -712 979 -456 -17 -356...

correct output
Yes

user output
Yes

Test 60

Verdict: ACCEPTED

input
1000
378 153 -125 298 -622 151 -554...

correct output
No

user output
No

Test 61

Verdict: ACCEPTED

input
100000
2482 97936 75560 -55358 -61956...

correct output
No

user output
No

Test 62

Verdict: ACCEPTED

input
100000
-48238 -24424 51980 7303 55103...

correct output
No

user output
No

Test 63

Verdict: ACCEPTED

input
100000
74971 50837 90459 -64742 -7834...

correct output
No

user output
No

Test 64

Verdict: ACCEPTED

input
100000
-62002 67632 -67632 62002 8747...

correct output
No

user output
No

Test 65

Verdict: ACCEPTED

input
100000
-69625 37139 -26540 -24951 357...

correct output
Yes

user output
Yes