Submission #1093698

#TimeUsernameProblemLanguageResultExecution timeMemory
1093698kemCircle Passing (EGOI24_circlepassing)C++14
31 / 100
78 ms11252 KiB
#include <bits/stdc++.h>
using namespace std;

#define NAME "name"

#define ll long long
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"

#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

const int LIM = 2e5 + 3;
const int INF = 1e9;
const int mod = 1e9 + 7;

int n, m, q;
pii p[LIM];
vector<int> num;

int dist(int x, int y)
{
    return min((x - y + (2 * n)) % (2 * n), (y - x + (2 * n)) % (2 * n));
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if (ifstream(NAME ".inp"))
    {
        freopen(NAME ".inp", "r", stdin);
        freopen(NAME ".out", "w", stdout);
    }

    cin >> n >> m >> q;
    memset(p, -1, sizeof(p));
    for (int i = 1; i <= m; i++)
    {
        int x;
        cin >> x;
        num.pb(x);
        num.pb(x + n);
    }
    sort(all(num));
    num.erase(unique(all(num)), num.end());
    while (q--)
    {
        int x, y;
        cin >> x >> y;
        int pos1 = lower_bound(all(num), x) - num.begin(), pos2 = (pos1 ? pos1 : sz(num)) - 1;
        cout << min(dist(x, y), min(dist(x, num[pos1]) + 1 + dist(num[pos1] + n * ((num[pos1] >= n) ? -1 : 1), y),
                                    dist(x, num[pos2]) + 1 + dist(num[pos2] + n * ((num[pos2] >= n) ? -1 : 1), y)))
             << endl;
    }

    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:43:28: warning: 'void* memset(void*, int, size_t)' writing to an object of type 'struct std::pair<int, int>' with no trivial copy-assignment [-Wclass-memaccess]
   43 |     memset(p, -1, sizeof(p));
      |                            ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<int, int>' declared here
  211 |     struct pair
      |            ^~~~
Main.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(NAME ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(NAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...