QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#455844#4383. Laserhorzward#AC ✓61ms4960kbC++172.6kb2024-06-26 21:31:072024-06-26 21:31:08

Judging History

你现在查看的是最新测评结果

  • [2024-06-26 21:31:08]
  • 评测
  • 测评结果:AC
  • 用时:61ms
  • 内存:4960kb
  • [2024-06-26 21:31:07]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#define ll long long
#define fastio ios::sync_with_stdio(0), cin.tie(0)

using namespace std;

const int N = 1e5 + 10;
int x[N];
int y[N];

bool yes(int k, int n)
{
    int tmpx[n + 1] = {0};
    int tmpy[n + 1] = {0};
    // 0, 45, 90, 135
    for(int i = 1; i <= n; i++) {
        if(k == 0) {
            tmpx[i] = x[i];
            tmpy[i] = y[i];
        }
        else if(k == 1) { // 45
            tmpx[i] = x[i] + y[i];
            tmpy[i] = x[i] - y[i];
        }
        else if(k == 2) {
            tmpx[i] = y[i];
            tmpy[i] = x[i];
        }
        else {
            tmpx[i] = x[i] - y[i];
            tmpy[i] = x[i] + y[i];
        }
    }
    // a line
    bool flag = 1;
    int line_index = -1;
    for(int i = 2; i <= n; i++) {
        if(tmpx[i] != tmpx[1]) {
            flag = 0;
            line_index = i;
        }
    }
    if(flag) {
        return 1;
    }
    // 90
    int nowx = tmpx[1];
    int nowy = tmpy[line_index];
    flag = 1;
    for(int i = 1; i <= n; i++) {
        if(tmpx[i] != nowx && tmpy[i] != nowy && nowx + nowy != tmpx[i] + tmpy[i] && nowx - nowy != tmpx[i] - tmpy[i]) {
            flag = 0;
            break;
        }
    }
    if(flag) {
        return 1;
    }
    // 45
    nowx = tmpx[1];
    nowy = tmpy[line_index] - (tmpx[line_index] - tmpx[1]);
    flag = 1;
    for(int i = 1; i <= n; i++) {
        if(tmpx[i] != nowx && tmpy[i] != nowy && nowx + nowy != tmpx[i] + tmpy[i] && nowx - nowy != tmpx[i] - tmpy[i]) {
            flag = 0;
            break;
        }
    }
    if(flag) {
        return 1;
    }
    // 135
    nowx = tmpx[1];
    nowy = tmpy[line_index] + (tmpx[line_index] - tmpx[1]);
        flag = 1;
    for(int i = 1; i <= n; i++) {
        if(tmpx[i] != nowx && tmpy[i] != nowy && nowx + nowy != tmpx[i] + tmpy[i] && nowx - nowy != tmpx[i] - tmpy[i]) {
            flag = 0;
            break;
        }
    }
    if(flag) {
        return 1;
    }
    return 0;
}

void solve()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i < 4; i++) {
        if(yes(i, n)) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 61ms
memory: 4960kb

input:

116
4
-10 0
10 0
5 5
-5 -5
4
-10 0
10 0
0 10
0 -10
4
-1 0
1 0
2 0
3 0
4
0 1
0 2
0 3
0 4
4
100 100
10000 10000
100000 100000
-100 -100
4
-100 100
-10000 10000
-100000 100000
100 -100
6
1 1
1 3
2 2
3 1
3 3
3 4
7
1 1
1 3
2 2
3 1
3 3
1 4
3 4
4
1236833 14678
1232056 9901
1237055 9790
1231834 15011
4
1236...

output:

YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO...

result:

ok 116 lines