답안 #624414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624414 2022-08-08T08:29:37 Z andrei_boaca 전차 (CEOI13_tram) C++14
65 / 100
1000 ms 2056 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll n,m;
bool have[150005][3];
set<ll> s;
pii where[30005];
ll dist(ll a, ll b, ll c, ll d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
int rgt[150005],lft[150005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    int cur=0;
    have[0][1]=have[0][2]=1;
    have[n+1][1]=have[n+1][2]=1;
    rgt[0]=n+1;
    while(m--)
    {
        cur++;
        char c;
        cin>>c;
        if(c=='E')
        {
            /*if(s.empty())
            {
                cout<<1<<' '<<1<<'\n';
                s.insert(1);
                have[1][1]=1;
                where[cur]={1,1};
                continue;
            }*/
            vector<int> v;
            int poz=0;
            while(true)
            {
                v.push_back(poz);
                if(poz==n+1)
                    break;
                poz=rgt[poz];
            }
            ll dmax=0;
            int mylft,myrgt;
            pii who;
            for(int i=1;i<v.size();i++)
            {
                int st=v[i-1];
                int dr=v[i];
                int mij=(st+dr)/2;
                for(int a=st;a<=st+1;a++)
                    if(a>=st&&a<=dr&&a>=1&&a<=n)
                        for(int j=1;j<=2;j++)
                            if(!have[a][j])
                            {
                                ll minim=1e18;
                                for(int k=1;k<=2;k++)
                                {
                                    if(have[st][k]&&st>0)
                                        minim=min(minim,dist(st,k,a,j));
                                    if(have[dr][k]&&dr<=n)
                                        minim=min(minim,dist(dr,k,a,j));
                                }
                                if(minim>dmax)
                                {
                                    dmax=minim;
                                    who={a,j};
                                    mylft=st;
                                    myrgt=dr;
                                }
                            }
                for(int a=mij;a<=mij+1;a++)
                    if(a>=st&&a<=dr&&a>=1&&a<=n)
                        for(int j=1;j<=2;j++)
                            if(!have[a][j])
                            {
                                ll minim=1e18;
                                for(int k=1;k<=2;k++)
                                {
                                    if(have[st][k]&&st>0)
                                        minim=min(minim,dist(st,k,a,j));
                                    if(have[dr][k]&&dr<=n)
                                        minim=min(minim,dist(dr,k,a,j));
                                }
                                if(minim>dmax)
                                {
                                    dmax=minim;
                                    who={a,j};
                                    mylft=st;
                                    myrgt=dr;
                                }
                            }
                for(int a=dr-1;a<=dr;a++)
                    if(a>=st&&a<=dr&&a>=1&&a<=n)
                        for(int j=1;j<=2;j++)
                            if(!have[a][j])
                            {
                                ll minim=1e18;
                                for(int k=1;k<=2;k++)
                                {
                                    if(have[st][k]&&st>0)
                                        minim=min(minim,dist(st,k,a,j));
                                    if(have[dr][k]&&dr<=n)
                                        minim=min(minim,dist(dr,k,a,j));
                                }
                                if(minim>dmax)
                                {
                                    dmax=minim;
                                    who={a,j};
                                    mylft=st;
                                    myrgt=dr;
                                }
                            }
            }
            cout<<who.first<<' '<<who.second<<'\n';
            have[who.first][who.second]=1;
            int g=who.first;
            where[cur]=who;
            if(have[g][1]+have[g][2]==1)
            {
                rgt[mylft]=g;
                rgt[g]=myrgt;
                lft[g]=mylft;
                lft[myrgt]=g;
            }
        }
        else
        {
            int p;
            cin>>p;
            int lin=where[p].first,col=where[p].second;
            have[lin][col]=0;
            if(have[lin][1]+have[lin][2]==0)
            {
                int L=lft[lin];
                int R=rgt[lin];
                rgt[L]=R;
                lft[R]=L;
            }
        }
    }
    return 0;
}

Compilation message

tram.cpp: In function 'int main()':
tram.cpp:51:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             for(int i=1;i<v.size();i++)
      |                         ~^~~~~~~~~
tram.cpp:129:27: warning: 'myrgt' may be used uninitialized in this function [-Wmaybe-uninitialized]
  129 |                 lft[myrgt]=g;
      |                 ~~~~~~~~~~^~
tram.cpp:128:23: warning: 'mylft' may be used uninitialized in this function [-Wmaybe-uninitialized]
  128 |                 lft[g]=mylft;
      |                 ~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 368 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 16 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 372 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 19 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 1952 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 18 ms 1960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 1960 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 17 ms 1964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1096 ms 2056 KB Time limit exceeded
2 Halted 0 ms 0 KB -