Submission #863852

# Submission time Handle Problem Language Result Execution time Memory
863852 2023-10-21T09:10:23 Z Tenis0206 Tram (CEOI13_tram) C++11
45 / 100
1000 ms 6804 KB
#include <bits/stdc++.h>

using namespace std;

const int oo = INT_MAX;
const int nmax = 150000;

int n,m;

int p[nmax + 5][3], l[nmax + 5][3], r[nmax + 5][3];

pair<int,int> poz[nmax + 5];

void Add(int nr)
{
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=2; j++)
        {
            if(p[i][j])
            {
                l[i][j] = i;
            }
            else
            {
                l[i][j] = l[i - 1][j];
            }
        }
    }

    for(int i=n; i>=1; i--)
    {
        for(int j=1; j<=2; j++)
        {
            if(p[i][j])
            {
                r[i][j] = i;
            }
            else
            {
                r[i][j] = r[i + 1][j];
            }
        }
    }

    int val = 0;
    int lin = 0, col = 0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1;j<=2;j++)
        {
            if(p[i][j])
            {
                continue;
            }
            int dist = oo;
            for(int lj=1;lj<=2;lj++)
            {
                if(l[i][lj])
                {
                    dist = min(dist, (i - l[i][lj]) * (i - l[i][lj]) + abs(j - lj));
                }
                if(r[i][lj])
                {
                    dist = min(dist, (r[i][lj] - i) * (r[i][lj] - i) + abs(j - lj));
                }
            }
            if(dist > val)
            {
                val = dist;
                lin = i;
                col = j;
            }
        }
    }
    p[lin][col] = nr;
    poz[nr] = {lin,col};
    cout<<lin<<' '<<col<<'\n';
}

void Remove(int nr)
{
    int lin = poz[nr].first;
    int col = poz[nr].second;
    p[lin][col] = 0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifdef home
    freopen("nr.in","r",stdin);
    freopen("nr.out","w",stdout);
#endif // home
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        char tip;
        cin>>tip;
        if(tip=='E')
        {
            Add(i);
        }
        else
        {
            int nr = 0;
            cin>>nr;
            Remove(nr);
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 472 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 23 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 19 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1006 ms 6804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1006 ms 6576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1036 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 6684 KB Time limit exceeded
2 Halted 0 ms 0 KB -