답안 #1058260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1058260 2024-08-14T09:08:55 Z SzymonKrzywda Circle Passing (EGOI24_circlepassing) C++17
100 / 100
187 ms 6596 KB
#include <bits/stdc++.h>

using namespace std;
int n;

int odl(int a, int b){
    int wynik=abs(a-b);
    wynik = min(wynik, (2*n)-max(a,b)+min(a,b));
    return wynik;
}

int main()
{
    int m,q,a,b;
    cin >> n >> m >> q;
    vector<int> pary(0);
    
    for (int i=0; i<m; i++){
        cin >> a;
        pary.push_back(a);
        pary.push_back(a+n);
        
    }

    sort(pary.begin(),pary.end());

/*
    //for (auto [i_1,i_2] : pary) cout << i_1 << " " << i_2 << endl;
    //liczymy pierwszy na lewo
    int akt_para = 1;
    int akt_idx = pary[0];
    
    vector<int> lewo(2*n);
    
    for (int i=0; i<2*n; i++){
        if (akt_para < pary.size() && pary[akt_para]==akt_idx){
            akt_para++;
        }
        //cout << akt_idx << endl;
        lewo[akt_idx] = pary[akt_para-1];
        cout << akt_idx << " " << lewo[akt_idx] << endl;
        akt_idx = (akt_idx+1)%(2*n);

    }

    //Liczymy pierwszy na prawo
    akt_para = (2*m)-2;
    akt_idx = pary[(2*m)-1];
    
    vector<int> prawo(2*n);

    for (int i=0; i<2*n; i++){
        //cout << "DUPA " << (akt_idx-1+(2*n))%(2*n) << " " << akt_idx <<  endl;
        if (akt_para >=0 && pary[akt_para]==akt_idx){
            akt_para--;
        }
        prawo[akt_idx] = pary[akt_para+1];
        cout << akt_idx << " " << prawo[akt_idx] << endl;
        akt_idx = (akt_idx-1+(2*n))%(2*n);
    }*/



    for (int i=0; i<q; i++){
        
                
        cin >> a >> b;
        int lewo,prawo;
        //prawo
        
        int lewo_=0,prawo_=(2*m)-1;
        while (lewo_<prawo_){
            int mid = (lewo_+prawo_)/2;
            //cout << lewo_ << " " << prawo_ << " " << mid << endl;
            if (pary[mid]>=a) prawo_=mid;
            else lewo_ = mid+1;
        }
        
        if (pary[lewo_]>=a) prawo = pary[lewo_];
        else prawo = pary[0];
        
        
        
        //lewo
        
        lewo_=0,prawo_=(2*m)-1;
        while (lewo_<prawo_){
            int mid = (lewo_+prawo_+1)/2;
            //cout << "TU: " << lewo_ << " " << prawo_ << " " << mid << endl;
            if (pary[mid]<=a) lewo_=mid;
            else prawo_ = mid-1;
        }
        //cout << pary[lewo_] << " " << lewo_ << endl;
        if (pary[lewo_]<=a) lewo = pary[lewo_];
        else lewo = pary[(2*m)-1];
        
        
        //cout << a << " " << b<< " " << lewo << " " << prawo << endl;

        
        int wynik = odl(a,b);
        wynik = min(wynik, 1+odl(a,prawo) + odl(((prawo+n)%(2*n)), b));
        wynik = min(wynik, 1+odl(a,lewo) + odl(((lewo+n)%(2*n)), b));
        cout << wynik << endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 344 KB Output is correct
2 Correct 21 ms 456 KB Output is correct
3 Correct 21 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 24 ms 524 KB Output is correct
6 Correct 24 ms 488 KB Output is correct
7 Correct 26 ms 600 KB Output is correct
8 Correct 27 ms 604 KB Output is correct
9 Correct 27 ms 604 KB Output is correct
10 Correct 26 ms 604 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 432 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 432 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 2 ms 344 KB Output is correct
45 Correct 2 ms 344 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 456 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 122 ms 5508 KB Output is correct
4 Correct 43 ms 1488 KB Output is correct
5 Correct 26 ms 604 KB Output is correct
6 Correct 24 ms 476 KB Output is correct
7 Correct 24 ms 604 KB Output is correct
8 Correct 26 ms 516 KB Output is correct
9 Correct 24 ms 600 KB Output is correct
10 Correct 25 ms 472 KB Output is correct
11 Correct 24 ms 532 KB Output is correct
12 Correct 25 ms 604 KB Output is correct
13 Correct 24 ms 592 KB Output is correct
14 Correct 25 ms 600 KB Output is correct
15 Correct 85 ms 2512 KB Output is correct
16 Correct 75 ms 2504 KB Output is correct
17 Correct 149 ms 5564 KB Output is correct
18 Correct 187 ms 6248 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 344 KB Output is correct
2 Correct 21 ms 456 KB Output is correct
3 Correct 21 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 24 ms 524 KB Output is correct
6 Correct 24 ms 488 KB Output is correct
7 Correct 26 ms 600 KB Output is correct
8 Correct 27 ms 604 KB Output is correct
9 Correct 27 ms 604 KB Output is correct
10 Correct 26 ms 604 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 432 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 3 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 344 KB Output is correct
57 Correct 2 ms 344 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 30 ms 456 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 122 ms 5508 KB Output is correct
68 Correct 43 ms 1488 KB Output is correct
69 Correct 26 ms 604 KB Output is correct
70 Correct 24 ms 476 KB Output is correct
71 Correct 24 ms 604 KB Output is correct
72 Correct 26 ms 516 KB Output is correct
73 Correct 24 ms 600 KB Output is correct
74 Correct 25 ms 472 KB Output is correct
75 Correct 24 ms 532 KB Output is correct
76 Correct 25 ms 604 KB Output is correct
77 Correct 24 ms 592 KB Output is correct
78 Correct 25 ms 600 KB Output is correct
79 Correct 85 ms 2512 KB Output is correct
80 Correct 75 ms 2504 KB Output is correct
81 Correct 149 ms 5564 KB Output is correct
82 Correct 187 ms 6248 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 20 ms 460 KB Output is correct
85 Correct 28 ms 448 KB Output is correct
86 Correct 22 ms 344 KB Output is correct
87 Correct 0 ms 348 KB Output is correct
88 Correct 24 ms 528 KB Output is correct
89 Correct 24 ms 588 KB Output is correct
90 Correct 27 ms 596 KB Output is correct
91 Correct 26 ms 600 KB Output is correct
92 Correct 27 ms 600 KB Output is correct
93 Correct 26 ms 456 KB Output is correct
94 Correct 1 ms 348 KB Output is correct
95 Correct 1 ms 348 KB Output is correct
96 Correct 2 ms 348 KB Output is correct
97 Correct 1 ms 348 KB Output is correct
98 Correct 2 ms 348 KB Output is correct
99 Correct 1 ms 348 KB Output is correct
100 Correct 1 ms 348 KB Output is correct
101 Correct 1 ms 348 KB Output is correct
102 Correct 1 ms 348 KB Output is correct
103 Correct 1 ms 348 KB Output is correct
104 Correct 1 ms 348 KB Output is correct
105 Correct 1 ms 348 KB Output is correct
106 Correct 1 ms 348 KB Output is correct
107 Correct 0 ms 348 KB Output is correct
108 Correct 0 ms 348 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 1 ms 348 KB Output is correct
111 Correct 3 ms 348 KB Output is correct
112 Correct 2 ms 348 KB Output is correct
113 Correct 3 ms 348 KB Output is correct
114 Correct 1 ms 348 KB Output is correct
115 Correct 2 ms 348 KB Output is correct
116 Correct 3 ms 344 KB Output is correct
117 Correct 2 ms 348 KB Output is correct
118 Correct 3 ms 348 KB Output is correct
119 Correct 3 ms 348 KB Output is correct
120 Correct 4 ms 348 KB Output is correct
121 Correct 126 ms 5156 KB Output is correct
122 Correct 76 ms 1476 KB Output is correct
123 Correct 24 ms 592 KB Output is correct
124 Correct 24 ms 560 KB Output is correct
125 Correct 24 ms 600 KB Output is correct
126 Correct 23 ms 476 KB Output is correct
127 Correct 58 ms 344 KB Output is correct
128 Correct 24 ms 504 KB Output is correct
129 Correct 46 ms 348 KB Output is correct
130 Correct 24 ms 512 KB Output is correct
131 Correct 50 ms 344 KB Output is correct
132 Correct 24 ms 604 KB Output is correct
133 Correct 79 ms 2560 KB Output is correct
134 Correct 86 ms 2500 KB Output is correct
135 Correct 167 ms 5988 KB Output is correct
136 Correct 161 ms 6596 KB Output is correct
137 Correct 169 ms 5376 KB Output is correct
138 Correct 178 ms 5316 KB Output is correct
139 Correct 24 ms 1608 KB Output is correct
140 Correct 10 ms 728 KB Output is correct
141 Correct 74 ms 2588 KB Output is correct
142 Correct 105 ms 2600 KB Output is correct
143 Correct 136 ms 5736 KB Output is correct
144 Correct 25 ms 540 KB Output is correct
145 Correct 27 ms 544 KB Output is correct
146 Correct 26 ms 604 KB Output is correct
147 Correct 29 ms 532 KB Output is correct
148 Correct 30 ms 596 KB Output is correct
149 Correct 32 ms 604 KB Output is correct
150 Correct 31 ms 608 KB Output is correct
151 Correct 0 ms 348 KB Output is correct
152 Correct 0 ms 348 KB Output is correct
153 Correct 0 ms 348 KB Output is correct
154 Correct 0 ms 348 KB Output is correct
155 Correct 0 ms 348 KB Output is correct