提出 #58211442
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// constants
const bool HAVE_CASE = false;
const ll MOD = 998244353;
// A C++ program to check if two given line segments intersect
#include <iostream>
using namespace std;
struct Point
{
int x;
int y;
};
// Given three collinear points p, q, r, the function checks if
// point q lies on line segment 'pr'
bool onSegment(Point p, Point q, Point r)
{
if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) &&
q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y))
return true;
return false;
}
// To find orientation of ordered triplet (p, q, r).
// The function returns following values
// 0 --> p, q and r are collinear
// 1 --> Clockwise
// 2 --> Counterclockwise
int orientation(Point p, Point q, Point r)
{
// See https://www.geeksforgeeks.org/orientation-3-ordered-points/
// for details of below formula.
int val = (q.y - p.y) * (r.x - q.x) -
(q.x - p.x) * (r.y - q.y);
if (val == 0) return 0; // collinear
return (val > 0)? 1: 2; // clock or counterclock wise
}
// The main function that returns true if line segment 'p1q1'
// and 'p2q2' intersect.
bool doIntersect(Point p1, Point q1, Point p2, Point q2)
{
// Find the four orientations needed for general and
// special cases
int o1 = orientation(p1, q1, p2);
int o2 = orientation(p1, q1, q2);
int o3 = orientation(p2, q2, p1);
int o4 = orientation(p2, q2, q1);
// General case
if (o1 != o2 && o3 != o4)
return true;
// Special Cases
// p1, q1 and p2 are collinear and p2 lies on segment p1q1
if (o1 == 0 && onSegment(p1, p2, q1)) return true;
// p1, q1 and q2 are collinear and q2 lies on segment p1q1
if (o2 == 0 && onSegment(p1, q2, q1)) return true;
// p2, q2 and p1 are collinear and p1 lies on segment p2q2
if (o3 == 0 && onSegment(p2, p1, q2)) return true;
// p2, q2 and q1 are collinear and q1 lies on segment p2q2
if (o4 == 0 && onSegment(p2, q1, q2)) return true;
return false; // Doesn't fall in any of the above cases
}
void test_case_run() {
int n;
cin >> n;
Point P[n+1], Q[n+1];
for (int i = 1; i <= n; i++) cin >> P[i].x >> P[i].y;
for (int i = 1; i <= n; i++) cin >> Q[i].x >> Q[i].y;
int R[n+1];
iota(R, R+n+1, 0);
bool pass = false;
for (int itr = 1; !pass && itr <= 2*n; itr++) {
pass = true;
for (int i = 1; i <= n; i++) {
for (int j = i+1; j <= n; j++) {
if (doIntersect(P[i], Q[R[i]], P[j], Q[R[j]])) {
pass = false;
swap(R[i], R[j]);
}
}
}
}
if (!pass) cout << -1;
else for (int i = 1; i <= n; i++) cout << R[i] << " ";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t = 1;
if (HAVE_CASE) cin >> t;
while (t--) test_case_run();
cout.flush();
return 0;
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
600 / 600 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 02_large_00.txt, 02_large_01.txt, 02_large_02.txt, 02_large_03.txt, 02_large_04.txt, 02_large_05.txt, 02_large_06.txt, 02_large_07.txt, 02_large_08.txt, 02_large_09.txt, 02_large_10.txt, 02_large_11.txt, 02_large_12.txt, 03_small_00.txt, 03_small_01.txt, 03_small_02.txt, 03_small_03.txt, 03_small_04.txt, 04_hand_00.txt, 04_hand_01.txt, 04_hand_02.txt, 04_hand_03.txt, 04_hand_04.txt, 04_hand_05.txt, 04_hand_06.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
1 ms |
3424 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3464 KiB |
| 01_random_00.txt |
AC |
2 ms |
3472 KiB |
| 01_random_01.txt |
AC |
2 ms |
3508 KiB |
| 01_random_02.txt |
AC |
1 ms |
3504 KiB |
| 01_random_03.txt |
AC |
1 ms |
3500 KiB |
| 01_random_04.txt |
AC |
1 ms |
3448 KiB |
| 01_random_05.txt |
AC |
2 ms |
3484 KiB |
| 01_random_06.txt |
AC |
1 ms |
3624 KiB |
| 01_random_07.txt |
AC |
1 ms |
3484 KiB |
| 01_random_08.txt |
AC |
2 ms |
3508 KiB |
| 01_random_09.txt |
AC |
1 ms |
3572 KiB |
| 01_random_10.txt |
AC |
1 ms |
3440 KiB |
| 01_random_11.txt |
AC |
1 ms |
3568 KiB |
| 01_random_12.txt |
AC |
1 ms |
3496 KiB |
| 01_random_13.txt |
AC |
1 ms |
3372 KiB |
| 01_random_14.txt |
AC |
2 ms |
3504 KiB |
| 01_random_15.txt |
AC |
1 ms |
3468 KiB |
| 01_random_16.txt |
AC |
1 ms |
3560 KiB |
| 01_random_17.txt |
AC |
2 ms |
3508 KiB |
| 01_random_18.txt |
AC |
1 ms |
3444 KiB |
| 01_random_19.txt |
AC |
1 ms |
3408 KiB |
| 02_large_00.txt |
AC |
3 ms |
3440 KiB |
| 02_large_01.txt |
AC |
3 ms |
3460 KiB |
| 02_large_02.txt |
AC |
3 ms |
3436 KiB |
| 02_large_03.txt |
AC |
3 ms |
3500 KiB |
| 02_large_04.txt |
AC |
3 ms |
3508 KiB |
| 02_large_05.txt |
AC |
3 ms |
3480 KiB |
| 02_large_06.txt |
AC |
3 ms |
3432 KiB |
| 02_large_07.txt |
AC |
4 ms |
3508 KiB |
| 02_large_08.txt |
AC |
3 ms |
3504 KiB |
| 02_large_09.txt |
AC |
3 ms |
3376 KiB |
| 02_large_10.txt |
AC |
3 ms |
3568 KiB |
| 02_large_11.txt |
AC |
3 ms |
3480 KiB |
| 02_large_12.txt |
AC |
3 ms |
3632 KiB |
| 03_small_00.txt |
AC |
1 ms |
3428 KiB |
| 03_small_01.txt |
AC |
1 ms |
3564 KiB |
| 03_small_02.txt |
AC |
1 ms |
3364 KiB |
| 03_small_03.txt |
AC |
1 ms |
3480 KiB |
| 03_small_04.txt |
AC |
1 ms |
3428 KiB |
| 04_hand_00.txt |
AC |
1 ms |
3492 KiB |
| 04_hand_01.txt |
AC |
1 ms |
3364 KiB |
| 04_hand_02.txt |
AC |
1 ms |
3420 KiB |
| 04_hand_03.txt |
AC |
1 ms |
3492 KiB |
| 04_hand_04.txt |
AC |
1 ms |
3364 KiB |
| 04_hand_05.txt |
AC |
1 ms |
3428 KiB |
| 04_hand_06.txt |
AC |
1 ms |
3496 KiB |