CSES - Aalto Competitive Programming 2024 - wk11 - Wed - Results
Submission details
Task:Match polygons
Sender:bubu2006
Submission time:2024-11-20 17:08:06 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#20.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#70.00 sdetails
#8ACCEPTED0.00 sdetails
#90.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#120.00 sdetails
#130.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#200.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#24ACCEPTED0.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#280.00 sdetails
#29ACCEPTED0.00 sdetails
#30ACCEPTED0.00 sdetails
#31ACCEPTED0.00 sdetails
#32ACCEPTED0.00 sdetails
#330.00 sdetails
#34ACCEPTED0.00 sdetails
#35ACCEPTED0.00 sdetails
#360.00 sdetails
#37ACCEPTED0.00 sdetails
#38ACCEPTED0.00 sdetails
#39ACCEPTED0.00 sdetails
#40ACCEPTED0.00 sdetails
#41ACCEPTED0.00 sdetails
#42ACCEPTED0.00 sdetails
#430.00 sdetails
#44ACCEPTED0.00 sdetails
#45ACCEPTED0.00 sdetails
#46ACCEPTED0.00 sdetails
#47ACCEPTED0.00 sdetails
#480.00 sdetails
#49ACCEPTED0.00 sdetails
#50ACCEPTED0.00 sdetails
#51ACCEPTED0.00 sdetails
#520.00 sdetails
#53ACCEPTED0.00 sdetails
#54ACCEPTED0.00 sdetails
#55ACCEPTED0.00 sdetails
#560.00 sdetails
#57ACCEPTED0.00 sdetails
#580.00 sdetails
#59ACCEPTED0.00 sdetails
#60ACCEPTED0.00 sdetails
#61ACCEPTED0.01 sdetails
#62ACCEPTED0.01 sdetails
#630.01 sdetails
#64ACCEPTED0.01 sdetails
#65ACCEPTED0.01 sdetails
#66ACCEPTED0.01 sdetails
#67ACCEPTED0.01 sdetails
#680.01 sdetails
#69ACCEPTED0.01 sdetails
#700.01 sdetails
#71ACCEPTED0.23 sdetails
#720.23 sdetails
#730.23 sdetails
#74ACCEPTED0.23 sdetails
#75ACCEPTED0.23 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:156:5: note: in expansion of macro 'debug'
  156 |     debug(aa);
      |     ^~~~~
input/code.cpp:60:20: warning: statement has no effect [-Wunused-value]
   60 | #define debug(...) 42
      |                    ^~
input/code.cpp:157:5: note: in expansion of macro 'debug'
  157 |     debug(bb);
      |     ^~~~~

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

/**
 * Author: Ulf Lundstrom
 * Date: 2009-02-26
 * License: CC0
 * Source: My head with inspiration from tinyKACTL
 * Description: Class to handle points in the plane.
 *     T can be e.g. double or long long. (Avoid int.)
 * Status: Works fine, used a lot
 */

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
    typedef Point P;
    T x, y;
    explicit Point(T x=0, T y=0) : x(x), y(y) {}
    bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
    bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
    P operator+(P p) const { return P(x+p.x, y+p.y); }
    P operator-(P p) const { return P(x-p.x, y-p.y); }
    P operator*(T d) const { return P(x*d, y*d); }
    P operator/(T d) const { return P(x/d, y/d); }
    T dot(P p) const { return x*p.x + y*p.y; }
    T cross(P p) const { return x*p.y - y*p.x; }
    T cross(P a, P b) const { return (a-*this).cross(b-*this); }
    T dist2() const { return x*x + y*y; }
    double dist() const { return sqrt((double)dist2()); }
    // angle to x-axis in interval [-pi, pi]
    double angle() const { return atan2(y, x); }
    P unit() const { return *this/dist(); } // makes dist()=1
    P perp() const { return P(-y, x); } // rotates +90 degrees
    P normal() const { return perp().unit(); }
    // returns point rotated 'a' radians ccw around the origin
    P rotate(double a) const {
        return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
    friend ostream& operator<<(ostream& os, P p) {
        return os << "(" << p.x << "," << p.y << ")"; }
};

typedef long double ld;

ld angle(Point<ld> a, Point<ld> b) {
    return atan2(a.cross(b), a.dot(b));
}

/**
 * Author: chilli
 * License: CC0
 * Description: z[i] computes the length of the longest common prefix of s[i:] and s,
 * except z[0] = 0. (abacaba -> 0010301)
 * Time: O(n)
 * Status: stress-tested
 */

const ld eps = 1e-9;
vi Z(const vector<ld>& S) {
    vi z(sz(S));
    int l = -1, r = -1;
    rep(i,1,sz(S)) {
        z[i] = i >= r ? 0 : min(r - i, z[i - l]);
        while (i + z[i] < sz(S) && abs(S[i + z[i]] - S[z[i]]) <= eps)
            z[i]++;
        if (i + z[i] > r)
            l = i, r = i + z[i];
    }
    return z;
}

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

    vector<Point<ld>> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
    for(int i=0;i<n;i++)cin>>b[i].x>>b[i].y;
    
    vector<ld> aa;
    for(int i=0;i<n;i++){
        int ii=(i+1)%n;
        int iii=(ii+1)%n;
        aa.push_back(angle(a[ii]-a[i],a[iii]-a[ii]));
    }

    vector<ld> bb;
    for(int i=0;i<n;i++){
        int ii=(i+1)%n;
        int iii=(ii+1)%n;
        bb.push_back(angle(b[ii]-b[i],b[iii]-b[ii]));
    }

    debug(aa);
    debug(bb);

    vector<ld> v;
    for (int i=0;i<n;i++)aa.push_back(aa[i]);
    
    for (auto x:bb)v.push_back(x);
    v.push_back(1000000); // hopefully
    for (auto x:aa)v.push_back(x);

    vi z = Z(v);
    for (int i=0;i<2*n;i++){
        if(z[i+n+1]==n){
            cout<<"Yes";
            return 0;
        }
    }
    cout << "No";
}

Test details

Test 1

Verdict: ACCEPTED

input
3
145.8941152374 -62.4127899333
215.1893651096 102.7633705745
44.8831775826 -76.3452030143
28.8949217210 68.0445638671
...

correct output
No

user output
No

Test 2

Verdict:

input
3
-197.6674322206 -353.244107216...

correct output
Yes

user output
No

Test 3

Verdict: ACCEPTED

input
3
-474.0737720427 49.6624761567
-169.6651796064 -295.351363915...

correct output
Yes

user output
Yes

Test 4

Verdict: ACCEPTED

input
3
10.8276009842 392.9469579759
396.2930912238 -374.4146840138
208.1478221972 -209.0952562075
-43.1667773180 149.1440517020
...

correct output
No

user output
No

Test 5

Verdict: ACCEPTED

input
3
214.8159946910 197.7288244779
47.2322534538 472.6843538631
-283.9104992809 476.2744547663
-71.1083540370 279.8609983382
...

correct output
Yes

user output
Yes

Test 6

Verdict: ACCEPTED

input
3
370.7323034888 -293.2808457801
111.7438615975 265.9078602206
418.6109044505 -11.5888097837
-426.5768989764 -0.3755815613
...

correct output
Yes

user output
Yes

Test 7

Verdict:

input
3
-168.0201953399 321.2291249562
-458.3033735249 -392.343323591...

correct output
Yes

user output
No

Test 8

Verdict: ACCEPTED

input
3
279.9187957373 -61.5907750747
38.4958717758 1.1204649377
223.4651800194 477.9895163271
-148.0958524894 -293.137314926...

correct output
Yes

user output
Yes

Test 9

Verdict:

input
3
30.8556874230 -267.2716731167
468.5406649977 369.1945386211
-488.6011964589 -69.5311823832
-76.7241898730 264.7261728057
...

correct output
Yes

user output
No

Test 10

Verdict: ACCEPTED

input
3
1.8745954997 -4.2267016836
-366.1704671086 -357.888907819...

correct output
Yes

user output
Yes

Test 11

Verdict: ACCEPTED

input
4
391.7730018258 463.6627640707
215.1893651096 102.7633705745
44.8831775826 -76.3452030143
145.8941152374 -62.4127899333
...

correct output
No

user output
No

Test 12

Verdict:

input
4
220.3244895202 -499.8856187024
-197.6674322206 -353.244107216...

correct output
Yes

user output
No

Test 13

Verdict:

input
4
-169.6651796064 -295.351363915...

correct output
Yes

user output
No

Test 14

Verdict: ACCEPTED

input
4
208.1478221972 -209.0952562075
-292.7571213710 -448.532791983...

correct output
No

user output
No

Test 15

Verdict: ACCEPTED

input
4
-283.9104992809 476.2744547663
214.8159946910 197.7288244779
47.2322534538 472.6843538631
-493.7697429619 -247.017638828...

correct output
Yes

user output
Yes

Test 16

Verdict: ACCEPTED

input
4
18.4179913146 -203.1995040629
370.7323034888 -293.2808457801
418.6109044505 -11.5888097837
111.7438615975 265.9078602206
...

correct output
Yes

user output
Yes

Test 17

Verdict: ACCEPTED

input
4
95.0520695152 29.8173602436
-81.1925694327 -164.5921507081
-168.0201953399 321.2291249562
-458.3033735249 -392.343323591...

correct output
Yes

user output
Yes

Test 18

Verdict: ACCEPTED

input
4
223.4651800194 477.9895163271
38.4958717758 1.1204649377
-427.9488664850 -231.561013865...

correct output
Yes

user output
Yes

Test 19

Verdict: ACCEPTED

input
4
-97.6486388207 22.6746672769
-488.6011964589 -69.5311823832
30.8556874230 -267.2716731167
468.5406649977 369.1945386211
...

correct output
No

user output
No

Test 20

Verdict:

input
4
-281.4413257844 -81.4918140235
-251.8988265336 -415.940346164...

correct output
Yes

user output
No

Test 21

Verdict: ACCEPTED

input
5
-116.5584786160 291.7250335397
215.1893651096 102.7633705745
44.8831775826 -76.3452030143
145.8941152374 -62.4127899333
...

correct output
No

user output
No

Test 22

Verdict: ACCEPTED

input
5
220.3244895202 -499.8856187024
38.8167321066 -80.8054807488
-154.4392748298 -103.232531186...

correct output
Yes

user output
Yes

Test 23

Verdict: ACCEPTED

input
5
119.2709705091 -200.3453226946
-169.6651796064 -295.351363915...

correct output
Yes

user output
Yes

Test 24

Verdict: ACCEPTED

input
5
396.2930912238 -374.4146840138
-292.7571213710 -448.532791983...

correct output
No

user output
No

Test 25

Verdict: ACCEPTED

input
5
214.8159946910 197.7288244779
47.2322534538 472.6843538631
-65.2084702386 279.3829260936
-493.7697429619 -247.017638828...

correct output
No

user output
No

Test 26

Verdict: ACCEPTED

input
5
418.6109044505 -11.5888097837
111.7438615975 265.9078602206
18.4179913146 -203.1995040629
-312.2787736378 -419.258730996...

correct output
Yes

user output
Yes

Test 27

Verdict: ACCEPTED

input
5
95.0520695152 29.8173602436
-458.3033735249 -392.343323591...

correct output
No

user output
No

Test 28

Verdict:

input
5
223.4651800194 477.9895163271
279.9187957373 -61.5907750747
-0.1175014731 179.2299907021
-427.9488664850 -231.561013865...

correct output
Yes

user output
No

Test 29

Verdict: ACCEPTED

input
5
-488.6011964589 -69.5311823832
-97.6486388207 22.6746672769
-21.6082081031 55.3564750418
468.5406649977 369.1945386211
...

correct output
No

user output
No

Test 30

Verdict: ACCEPTED

input
5
-366.1704671086 -357.888907819...

correct output
Yes

user output
Yes

Test 31

Verdict: ACCEPTED

input
10
215.1893651096 102.7633705745
370.0121452893 478.6183430976
332.6198429261 278.1567571119
-412.8707029537 -479.781600728...

correct output
No

user output
No

Test 32

Verdict: ACCEPTED

input
10
-197.6674322206 -353.244107216...

correct output
Yes

user output
Yes

Test 33

Verdict:

input
10
29.1420905428 -365.4200575121
13.5781179412 -315.5601370179
285.3351476881 353.9752909584
-5.7631594720 346.5614913514
...

correct output
Yes

user output
No

Test 34

Verdict: ACCEPTED

input
10
396.2930912238 -374.4146840138
10.8276009842 392.9469579759
208.1478221972 -209.0952562075
-84.8988037551 -216.4749136305
...

correct output
No

user output
No

Test 35

Verdict: ACCEPTED

input
10
214.8159946910 197.7288244779
-283.9104992809 476.2744547663
-493.7697429619 -247.017638828...

correct output
No

user output
No

Test 36

Verdict:

input
10
418.6109044505 -11.5888097837
370.7323034888 -293.2808457801
79.8378087402 99.9291982716
-203.9200667946 128.7879072777
...

correct output
Yes

user output
No

Test 37

Verdict: ACCEPTED

input
10
323.7594305076 -445.5254961601
-86.7990650067 376.2676519525
490.2242714829 319.8581971028
78.8586054090 145.3550910008
...

correct output
No

user output
No

Test 38

Verdict: ACCEPTED

input
10
279.9187957373 -61.5907750747
-475.1007730927 100.5489220262
-47.8760438631 431.2060235370
409.5935271290 -286.6146460422
...

correct output
Yes

user output
Yes

Test 39

Verdict: ACCEPTED

input
10
468.5406649977 369.1945386211
-281.1989388303 -434.191608273...

correct output
No

user output
No

Test 40

Verdict: ACCEPTED

input
10
-461.2516256201 199.1073919851
378.5590828200 450.9640294998
-154.5013572565 -333.223648952...

correct output
Yes

user output
Yes

Test 41

Verdict: ACCEPTED

input
100
-361.8170504185 -303.417643118...

correct output
No

user output
No

Test 42

Verdict: ACCEPTED

input
100
33.1652894178 191.8771127699
-184.4843660273 186.5009246725
334.6256736627 -481.7117197876
250.1443123990 488.8610876221
...

correct output
Yes

user output
Yes

Test 43

Verdict:

input
100
418.4586408585 92.0845730713
-153.7620872729 -236.221473534...

correct output
Yes

user output
No

Test 44

Verdict: ACCEPTED

input
100
448.5276483394 200.5117812008
251.0273075753 -156.9061412350
-269.1637320891 465.2933520511
34.7348709576 274.9678181440
...

correct output
No

user output
No

Test 45

Verdict: ACCEPTED

input
100
490.7968171326 -426.3476238374
-90.4086108461 262.8817904577
51.9264361054 -319.0351620088
425.8085958464 220.4521208745
...

correct output
No

user output
No

Test 46

Verdict: ACCEPTED

input
100
-74.3626661635 -76.1504015282
-181.3535649091 -134.666982828...

correct output
Yes

user output
Yes

Test 47

Verdict: ACCEPTED

input
100
168.1377296396 438.3926027826
286.0058594120 250.4304716281
-2.9490289955 -457.2674989056
316.8674938575 -486.3762628636
...

correct output
No

user output
No

Test 48

Verdict:

input
100
-350.5137011789 -476.809635525...

correct output
Yes

user output
No

Test 49

Verdict: ACCEPTED

input
100
-200.9472548840 365.4240335970
346.9465387115 -34.2996311811
251.3582001296 283.5706742682
-131.9031523480 -322.686901620...

correct output
No

user output
No

Test 50

Verdict: ACCEPTED

input
100
-363.3269953958 -83.5422447588
238.4628330597 84.3076344610
383.4332256402 78.7496102147
-322.0295442938 91.7516883536
...

correct output
Yes

user output
Yes

Test 51

Verdict: ACCEPTED

input
200
-172.2796022472 256.7786464273
136.0610565234 -259.9797261107
-339.4611774089 296.3914747838
459.1666030018 -41.8611750396
...

correct output
No

user output
No

Test 52

Verdict:

input
200
33.1652894178 191.8771127699
-184.4843660273 186.5009246725
334.6256736627 -481.7117197876
250.1443123990 488.8610876221
...

correct output
Yes

user output
No

Test 53

Verdict: ACCEPTED

input
200
200.7523435514 464.5510825450
80.0041831077 -337.7013967560
-113.1073493364 293.6374527898
-16.9301681094 5.2367171257
...

correct output
Yes

user output
Yes

Test 54

Verdict: ACCEPTED

input
200
360.5339118870 86.2529018574
-208.2072264492 -42.3136017743
-31.0597544157 -230.7644195975
-274.9454972746 -93.4800828538
...

correct output
No

user output
No

Test 55

Verdict: ACCEPTED

input
200
-478.6701591848 83.9198708060
-54.6429558156 342.0566538501
-300.9443485300 -59.4009511125
167.4545291040 -431.6653725926
...

correct output
No

user output
No

Test 56

Verdict:

input
200
49.4634593109 207.5262226064
-234.8873378290 -490.291688824...

correct output
Yes

user output
No

Test 57

Verdict: ACCEPTED

input
200
-194.4127520360 177.9625888294
135.4779960658 224.4061120463
-241.0205240694 -223.200325023...

correct output
No

user output
No

Test 58

Verdict:

input
200
-42.4011263057 395.3667842530
-442.7464391228 57.3176247339
-172.0889013916 -464.726660462...

correct output
Yes

user output
No

Test 59

Verdict: ACCEPTED

input
200
-399.6132030797 231.1584326536
-349.0298947219 36.1443047518
127.0556495233 -284.6822030259
-53.5770931326 -311.8274867595
...

correct output
No

user output
No

Test 60

Verdict: ACCEPTED

input
200
417.0287554196 194.5884938677
-363.9202956245 307.6956033342
-26.4321239562 -58.3468212421
-298.9623330859 404.6753463722
...

correct output
Yes

user output
Yes

Test 61

Verdict: ACCEPTED

input
1000
-169.4036997070 -448.946934805...

correct output
No

user output
No

Test 62

Verdict: ACCEPTED

input
1000
345.5176757164 320.2024696845
408.8080319057 -349.3100103728
-315.0649811086 65.7321453399
374.7476191883 202.9317391843
...

correct output
Yes

user output
Yes

Test 63

Verdict:

input
1000
219.6875435643 213.0072901918
269.8596571543 -169.2529716435
-271.3897492748 126.3439621773
-85.5207510408 436.7810746595
...

correct output
Yes

user output
No

Test 64

Verdict: ACCEPTED

input
1000
-360.5328729828 -186.180887851...

correct output
No

user output
No

Test 65

Verdict: ACCEPTED

input
1000
474.3704468638 -39.4976558160
-140.9809366535 -399.686457453...

correct output
No

user output
No

Test 66

Verdict: ACCEPTED

input
1000
436.9671382620 271.4579197691
279.0135301573 -485.3562019434
192.8559481123 -465.6796370956
254.8746088172 -75.0699801116
...

correct output
Yes

user output
Yes

Test 67

Verdict: ACCEPTED

input
1000
-187.5982099198 229.8238792093
3.5532439404 -456.8527777580
-208.7357286799 139.8281083868
468.5752076857 318.3348546534
...

correct output
No

user output
No

Test 68

Verdict:

input
1000
348.1110838687 186.1280973285
-126.3758471551 -407.922449821...

correct output
Yes

user output
No

Test 69

Verdict: ACCEPTED

input
1000
-386.0740098833 93.3802332762
-274.4602815315 187.5615193622
-13.4234250797 191.5405241327
-423.5354565059 50.7549107200
...

correct output
No

user output
No

Test 70

Verdict:

input
1000
-451.1004626587 149.3426100968
-211.2764645506 344.4102345563
-166.7031335983 421.3069957702
-368.6133048856 49.0049880385
...

correct output
Yes

user output
No

Test 71

Verdict: ACCEPTED

input
100000
-205.3245172610 -151.443930911...

correct output
No

user output
No

Test 72

Verdict:

input
100000
-96.6377474657 -267.3024156647
378.2164754911 315.8208359125
-382.8506882809 -109.238752477...

correct output
Yes

user output
No

Test 73

Verdict:

input
100000
171.1064190127 422.2639523115
-103.5929075564 480.2294932552
-126.3506574590 126.1145421587
-283.4265770635 -221.357530439...

correct output
Yes

user output
No

Test 74

Verdict: ACCEPTED

input
100000
-430.5032134612 -451.506257934...

correct output
No

user output
No

Test 75

Verdict: ACCEPTED

input
100000
-462.9306928679 -454.709734504...

correct output
No

user output
No