# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
624416 |
2022-08-08T08:30:15 Z |
andrei_boaca |
Tram (CEOI13_tram) |
C++14 |
|
1000 ms |
2124 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];
vector<int> v;
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;
}*/
v.clear();
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:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=1;i<v.size();i++)
| ~^~~~~~~~~
tram.cpp:130:27: warning: 'myrgt' may be used uninitialized in this function [-Wmaybe-uninitialized]
130 | lft[myrgt]=g;
| ~~~~~~~~~~^~
tram.cpp:129:23: warning: 'mylft' may be used uninitialized in this function [-Wmaybe-uninitialized]
129 | lft[g]=mylft;
| ~~~~~~^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
392 KB |
Output is correct |
2 |
Correct |
4 ms |
356 KB |
Output is correct |
3 |
Correct |
16 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
16 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
1968 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
18 ms |
1964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
1948 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
23 ms |
1996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1045 ms |
876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
2124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |