Submission #53090

# Submission time Handle Problem Language Result Execution time Memory
53090 2018-06-28T10:26:51 Z Costin Andrei Oncescu(#1297) Tram (CEOI13_tram) C++11
0 / 100
38 ms 4600 KB
#include<bits/stdc++.h>

using namespace std;

int N, M, K;
bool ap[150009][3];
pair < int, int > cell[30009];
set < int > S;
set < pair < long long, pair < int, int > > > PQ;

long long getDist (int x, int y, int c)
{
    long long d = 1LL * N * N + 3;
    if (ap[c][1]) d = min (d, 1LL * (x - c) * (x - c) + (y - 1));
    if (ap[c][2]) d = min (d, 1LL * (x - c) * (x - c) + (2 - y));
    return d;
}

pair < long long, pair < int, int > > getCell (int i, int j)
{
    if (i == 0 && j == N + 1) return {-1LL * N * N - 3, {1, 1}};
    if (i == 0)
    {
        if (j == 1)
        {
            if (ap[1][1] && ap[1][2]) return {0, {1, 1}};
            if (ap[1][1]) return {-1, {1, 2}};
            return {-1, {1, 1}};
        }
        int x = 1, y = 1;
        if (ap[j][2] == 0 && ap[j][1] == 1) y = 2;
        return {-getDist (x, y, j), {x, y}};
    }
    if (j == N + 1)
    {
        if (i == N)
        {
            if (ap[N][1] && ap[N][2]) return {0, {1, 1}};
            if (ap[N][1]) return {-1, {N, 2}};
            return {-1, {N, 1}};
        }
        int x = N, y = 1;
        if (ap[i][2] == 0 && ap[i][1] == 1) y = 2;
        return {-getDist (x, y, i), {x, y}};
    }
    int mij = (i + j) >> 1;
    long long maxi = 0;
    pair < int, int > ans = {1, 1};
    for (int k=mij; k<=mij + 1 && k<j; k++)
        for (int p=1; p<=2; p++)
        if (ap[k][p] == 0)
        {
            long long d = min (getDist (k, p, i), getDist (k, p, j));
            if (d > maxi)
                maxi = d, ans = {k, p};
        }
    return {-maxi, ans};
}

void add (int x, int y)
{
    auto it = S.lower_bound (x);
    if (*it != x)
    {
        auto it2 = it, it1 = it2; it1 --;
        auto curr = getCell (*it1, *it2);
        if (curr.first != 0) PQ.erase (curr);
        ap[x][y] = 1;
        curr = getCell (*it1, x);
        if (curr.first != 0) PQ.insert (curr);
        curr = getCell (x, *it2);
        if (curr.first != 0) PQ.insert (curr);
        S.insert (x);
        return ;
    }
    auto it2 = it, it1 = it;
    it1 --, it2 ++;
    auto curr = getCell (*it1, x);
    if (curr.first != 0) PQ.erase (curr);
    curr = getCell (x, *it2);
    if (curr.first != 0) PQ.erase (curr);
    ap[x][y] = 1;
    curr = getCell (*it1, x);
    if (curr.first != 0) PQ.insert (curr);
    curr = getCell (x, *it2);
    if (curr.first != 0) PQ.insert (curr);
}

void del (int x, int y)
{
    auto it = S.find (x);
    auto it1 = it, it2 = it;
    it1 --, it2 ++;
    auto curr = getCell (*it1, x);
    if (curr.first != 0) PQ.erase (curr);
    curr = getCell (x, *it2);
    if (curr.first != 0) PQ.erase (curr);
    if (ap[x][1] + ap[x][2] == 1)
    {
        ap[x][y] = 0;
        curr = getCell (*it1, *it2);
        if (curr.first != 0) PQ.insert (curr);
        S.erase (it);
        return ;
    }
    ap[x][y] = 0;
    curr = getCell (*it1, x);
    if (curr.first != 0) PQ.insert (curr);
    curr = getCell (x, *it2);
    if (curr.first != 0) PQ.insert (curr);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M);
S.insert (0), S.insert (N + 1);
PQ.insert (getCell (0, N + 1));
while (M --)
{
    char type;
    scanf ("\n%c", &type);
    K ++;
    if (type == 'E')
    {
        auto curr = *PQ.begin ();
        cell[K] = curr.second;
        printf ("%d %d\n", cell[K].first, cell[K].second);
        add (cell[K].first, cell[K].second);
/*        printf ("After ins: ");
        for (auto it : PQ)
            printf ("[(%d %d) %lld] ", it.second.first, it.second.second, -it.first);
        printf ("\n");*/
        continue;
    }
    int pos = 0;
    scanf ("%d", &pos);
    del (cell[pos].first, cell[pos].second);
/*    printf ("After del: ");
    for (auto it : PQ)
        printf ("[(%d %d) %lld] ", it.second.first, it.second.second, -it.first);
    printf ("\n");*/
}

return 0;
}

Compilation message

tram.cpp: In function 'int main()':
tram.cpp:118:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  118 | scanf ("%d %d", &N, &M);
      | ~~~~~~^~~~~~~~~~~~~~~~~
tram.cpp:124:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  124 |     scanf ("\n%c", &type);
      |     ~~~~~~^~~~~~~~~~~~~~~
tram.cpp:139:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  139 |     scanf ("%d", &pos);
      |     ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 876 KB Output is correct
2 Incorrect 3 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1036 KB Output is correct
2 Incorrect 2 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 2176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 4600 KB Output is correct
2 Incorrect 22 ms 748 KB Output isn't correct
3 Halted 0 ms 0 KB -