Submission #415036

#TimeUsernameProblemLanguageResultExecution timeMemory
415036CollypsoIdeal city (IOI12_city)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#define F first
#define S second
//#define endl '\n'
//#define int long long

#define inbuf_len 1 << 16
#define outbuf_len 1 << 16

const int MOD = 1e9;

using namespace std;

map<pii, int> filled;
map<pii, int> dist;

int bfs(pii start, int i)
{
    dist.clear();
    for(auto x : filled)
        if (x.S) dist[x.F] = INT_MAX;
    queue<pii> q;
    q.push(start);
    dist[start] = 0;
    while(!q.empty())
    {
        pii v = q.front();
        q.pop();

        int d = dist[{v.F, v.S}];
        if (filled[{v.F + 1, v.S}])
        {
            if (dist[{v.F + 1, v.S}] > d + 1)
                q.push({v.F + 1, v.S}), dist[{v.F + 1, v.S}] = d + 1;
        }
        if (filled[{v.F, v.S + 1}])
        {
            if (dist[{v.F, v.S + 1}] > d + 1)
                q.push({v.F, v.S + 1}), dist[{v.F, v.S + 1}] = d + 1;
        }
        if (filled[{v.F - 1, v.S}])
        {
            if (dist[{v.F - 1, v.S}] > d + 1)
                q.push({v.F - 1, v.S}), dist[{v.F - 1, v.S}] = d + 1;
        }
        if (filled[{v.F, v.S - 1}])
        {
            if (dist[{v.F, v.S - 1}] > d + 1)
                q.push({v.F, v.S - 1}), dist[{v.F, v.S - 1}] = d + 1;
        }
    }
    int ans = 0;
    for(auto x : dist)
    {
        if (filled[x.F] > i) ans = (1ll * ans + x.S) % MOD;
    }
    return ans;
}

int subtask12(int N, int* X, int* Y)
{
    for(int i = 0; i < N; i++)
        filled[{*(X + i), *(Y + i)}] = i + 1;
    int ans = 0;
    for(int i = 0; i < N; i++)
        ans = (1ll * ans + bfs({*(X + i), *(Y + i)}, i + 1)) % MOD;
    return ans;
}

int DistanceSum(int N, int* X, int* Y)
{
    if (N <= 2000) return subtask12(N, X, Y);

}

/**
main()
{
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int tmp;

    /* Set input and output buffering */
    char *inbuf, *outbuf;
    inbuf = (char*) malloc(inbuf_len * sizeof(char));
    outbuf = (char*) malloc(outbuf_len * sizeof(char));
    tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
    assert(tmp == 0);
    tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);
    assert(tmp == 0);

    int N, i;
    tmp = scanf("%d", &N);
    assert(tmp == 1);
    int *sq_x, *sq_y;
    sq_x = (int*) malloc(N * sizeof(int));
    sq_y = (int*) malloc(N * sizeof(int));
    for (i = 0; i < N; i++) {
        tmp = scanf("%d %d", &sq_x[i], &sq_y[i]);
        assert(tmp == 2);
    }
    int ds = DistanceSum(N, sq_x, sq_y);
    printf("%d\n", ds);
}
/**/

/*
11
2 5
2 6
3 3
3 6
4 3
4 4
4 5
4 6
5 3
5 4
5 6

20
3 5
4 6
2 5
3 4
6 5
1 6
2 7
3 1
2 6
1 5
5 5
5 4
4 7
4 2
3 2
3 3
4 4
4 3
4 5
5 2

*/

Compilation message (stderr)

city.cpp:92:5: warning: "/*" within comment [-Wcomment]
   92 |     /* Set input and output buffering */
      |      
city.cpp:94:5: error: 'inbuf' does not name a type
   94 |     inbuf = (char*) malloc(inbuf_len * sizeof(char));
      |     ^~~~~
city.cpp:95:5: error: 'outbuf' does not name a type
   95 |     outbuf = (char*) malloc(outbuf_len * sizeof(char));
      |     ^~~~~~
city.cpp:96:5: error: 'tmp' does not name a type; did you mean 'tm'?
   96 |     tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
      |     ^~~
      |     tm
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from city.cpp:1:
city.cpp:97:5: error: expected unqualified-id before 'static_cast'
   97 |     assert(tmp == 0);
      |     ^~~~~~
city.cpp:97:5: error: expected ')' before 'static_cast'
city.cpp:98:5: error: 'tmp' does not name a type; did you mean 'tm'?
   98 |     tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);
      |     ^~~
      |     tm
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from city.cpp:1:
city.cpp:99:5: error: expected unqualified-id before 'static_cast'
   99 |     assert(tmp == 0);
      |     ^~~~~~
city.cpp:99:5: error: expected ')' before 'static_cast'
city.cpp:102:5: error: 'tmp' does not name a type; did you mean 'tm'?
  102 |     tmp = scanf("%d", &N);
      |     ^~~
      |     tm
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from city.cpp:1:
city.cpp:103:5: error: expected unqualified-id before 'static_cast'
  103 |     assert(tmp == 1);
      |     ^~~~~~
city.cpp:103:5: error: expected ')' before 'static_cast'
city.cpp:105:5: error: 'sq_x' does not name a type
  105 |     sq_x = (int*) malloc(N * sizeof(int));
      |     ^~~~
city.cpp:106:5: error: 'sq_y' does not name a type
  106 |     sq_y = (int*) malloc(N * sizeof(int));
      |     ^~~~
city.cpp:107:5: error: expected unqualified-id before 'for'
  107 |     for (i = 0; i < N; i++) {
      |     ^~~
city.cpp:107:17: error: 'i' does not name a type
  107 |     for (i = 0; i < N; i++) {
      |                 ^
city.cpp:107:24: error: 'i' does not name a type
  107 |     for (i = 0; i < N; i++) {
      |                        ^
city.cpp:112:11: error: expected constructor, destructor, or type conversion before '(' token
  112 |     printf("%d\n", ds);
      |           ^
city.cpp:113:1: error: expected declaration before '}' token
  113 | }
      | ^
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:84:1: warning: control reaches end of non-void function [-Wreturn-type]
   84 | }
      | ^