QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#815988#9804. Guess the Polygonxuxin12345WA 7ms3844kbC++233.9kb2024-12-15 20:19:352024-12-15 20:19:36

Judging History

This is the latest submission verdict.

  • [2024-12-15 20:19:36]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 3844kb
  • [2024-12-15 20:19:35]
  • Submitted

answer

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

#define max_len 1200
#define int __int128_t
#define gcd my_gcd
int gcd(int __m, int __n)
{
    if (__m == 0)
        return __n;
    if (__n == 0)
        return __m;

    while (true)
    {
        if (__m > __n)
        {
            int __tmp = __m;
            __m = __n;
            __n = __tmp;
        }

        __n -= __m;

        if (__n == 0)
            return __m;
    }
};

struct frac_num
{
    int fz, fm;
    frac_num() = default;
    frac_num(int zz, int mm)
    {
        fz = zz, fm = mm;
        mk_gcd();
    }
    frac_num(int zz)
    {
        fz = zz, fm = 1;
    }
    void mk_gcd()
    {
        int g = gcd(fz, fm);
        fz = fz / g, fm = fm / g;
    }
    frac_num operator+(const frac_num &r) const
    {
        return frac_num(fz * r.fm + fm * r.fz, fm * r.fm);
    }
    frac_num operator-(const frac_num &r) const
    {
        return frac_num(fz * r.fm - fm * r.fz, fm * r.fm);
    }
    frac_num operator+(const int &r) const
    {
        return frac_num(fz + fm * r, fm);
    }
    frac_num operator-(const int &r) const
    {
        return frac_num(fz - fm * r, fm);
    }
    frac_num operator*(const frac_num &r) const
    {
        return frac_num(fz * r.fz, fm * r.fm);
    }
    frac_num operator*(const int r) const
    {
        return frac_num(fz * r, fm);
    }
    frac_num operator/(const int r) const
    {
        return frac_num(fz, fm * r);
    }
    bool operator==(const int r) const
    {
        return fm == 1 && fz == r;
    }
    // bool operator<(const int r) const
    // {
    //     return 1.0 * fz / fm < r;
    // }
    bool operator<(const frac_num &r) const
    {
        return fz * r.fm < fm * r.fz;
    }
};

frac_num print_ques(frac_num fn)
{
    fn.mk_gcd();
    cout << "? " << int32_t(fn.fz) << " " << int32_t(fn.fm) << endl;
    int32_t zz, mm;
    cin >> zz >> mm;
    return frac_num(zz, mm);
}
void print_ans(frac_num fn)
{
    fn.mk_gcd();
    cout << "! " << int32_t(fn.fz) << " " << int32_t(fn.fm) << endl;
}

int32_t N;
map<int, set<int>> poi_map;
void input()
{
    poi_map.clear();
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int32_t x, y;
        cin >> x >> y;
        poi_map[x].insert(y);
    }
}

void sol()
{
    input();
    // x, [y]
    vector<pair<frac_num, vector<int>>> poi_vec;
    bool is_y_cnt1 = true;
    for (auto [pir_x, pirs] : poi_map)
    {
        poi_vec.push_back({pir_x, vector<int>()});
        for (auto yy : pirs)
        {
            poi_vec.back().second.push_back(yy);
        }
        if (pirs.size() > 1)
        {
            is_y_cnt1 = false;
        }
    }
    int poi_su = poi_vec.size();
    frac_num ans = 0;

    if (is_y_cnt1 == true)
    {
        frac_num ans_m2 = 0;
        auto last_x = poi_vec.front().first;
        auto last_bian_len = frac_num(0, 1);
        for (int32_t i = 1; i < poi_su - 1; i++)
        {
            auto now_x = poi_vec[i].first;
            auto now_y_len = print_ques(now_x);
            ans_m2 = ans_m2 + (now_y_len + last_bian_len) * (now_x - last_x);
            last_bian_len = now_y_len;
            last_x = now_x;
        }
        auto end_x = poi_vec.back().first;
        ans_m2 = ans_m2 + (last_bian_len) * (end_x - last_x);

        ans = ans_m2 / 2;
    }
    else
    {
        auto last_x = poi_vec.front().first;
        for (int32_t i = 1; i < poi_su; i++)
        {
            auto now_x = poi_vec[i].first;
            auto mid_x = (last_x + now_x) / 2;
            auto now_y_len = print_ques(mid_x);
            ans = ans + (now_y_len) * (now_x - last_x);
            last_x = now_x;
        }
    }
    print_ans(ans);
}
int32_t main()
{
    int32_t T;
    cin >> T;
    while (T--)
    {
        sol();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3844kb

input:

2
4
3 0
1 3
1 1
0 0
1 1
1 1
3
0 0
999 1000
1000 999
1999 1000

output:

? 1 2
? 2 1
! 3 1
? 999 1
! 1999 2

result:

ok correct! (2 test cases)

Test #2:

score: 0
Accepted
time: 7ms
memory: 3548kb

input:

9
4
1 1
1 3
3 0
0 0
3 2
1 2
4
0 0
1 3
1 1
3 0
1 2
3 2
4
0 0
3 0
1 2
1 1
1 2
1 2
4
0 0
3 0
1 2
1 1
1 1
1 2
4
0 0
3 0
1 1
1 2
1 2
1 1
3
1000 0
0 0
0 1000
500 1
4
0 0
1000 0
1000 1000
0 1000
1000 1
5
0 1
1000 1000
1000 0
0 1000
1 0
1999 2
1000 1
9
4 1000
3 1
2 1000
3 1000
1 1
2 1
0 0
1 1000
4 0
500 1
1...

output:

? 1 2
? 2 1
! 5 2
? 1 2
? 2 1
! 7 2
? 1 2
? 2 1
! 3 2
? 1 2
? 2 1
! 2 1
? 1 2
? 2 1
! 5 2
? 500 1
! 500000 1
? 500 1
! 1000000 1
? 1 2
? 1001 2
! 1999999 2
? 1 2
? 3 2
? 5 2
? 7 2
! 4003 2

result:

ok correct! (9 test cases)

Test #3:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

78
8
951 614
927 614
957 614
957 604
937 614
942 619
951 610
927 604
10 1
25 2
21 2
10 1
7
562 260
602 250
582 255
587 260
602 260
562 250
577 260
10 1
15 2
15 2
10 1
3
454 98
494 68
455 68
117 4
3
526 589
566 559
527 559
117 4
3
854 496
854 466
894 466
15 1
3
797 264
827 254
857 264
10 1
3
719 737
...

output:

? 932 1
? 1879 2
? 1893 2
? 954 1
! 317 1
? 1139 2
? 1159 2
? 1169 2
? 1189 2
! 375 1
? 455 1
! 585 1
? 527 1
! 585 1
? 874 1
! 600 1
? 827 1
! 300 1
? 739 1
! 600 1
? 162 1
! 400 1
? 1489 2
? 1499 2
? 772 1
! 275 1
? 1869 2
? 1879 2
? 1889 2
? 1899 2
? 1909 2
? 1919 2
? 1929 2
? 1939 2
? 1949 2
? 1...

result:

ok correct! (78 test cases)

Test #4:

score: -100
Wrong Answer
time: 5ms
memory: 3624kb

input:

34
24
123 815
168 800
133 795
27 827
153 805
28 830
178 780
138 810
78 830
192 772
148 790
88 810
43 825
183 795
103 805
163 785
118 800
93 825
63 835
73 815
58 820
198 790
48 840
108 820
10 3
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
15 1
24...

output:

? 28 1
? 43 1
? 48 1
? 58 1
? 63 1
? 73 1
? 78 1
? 88 1
? 93 1
? 103 1
? 108 1
? 118 1
? 123 1
? 133 1
? 138 1
? 148 1
? 153 1
? 163 1
? 168 1
? 178 1
? 183 1
? 192 1
! 1925 1
? 54 1
? 69 1
? 74 1
? 84 1
? 89 1
? 99 1
? 104 1
? 114 1
? 119 1
? 129 1
? 134 1
? 144 1
? 149 1
? 159 1
? 164 1
? 174 1
? ...

result:

wrong answer Integer parameter [name=x] equals to 134450457, violates the range [0, 2000000] (test case 27)