# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
624409 |
2022-08-08T08:20:47 Z |
andrei_boaca |
Tram (CEOI13_tram) |
C++14 |
|
1000 ms |
1264 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 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;
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;
v.push_back(0);
for(int i:s)
v.push_back(i);
v.push_back(n+1);
ll dmax=0;
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=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};
}
}
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};
}
}
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};
}
}
}
cout<<who.first<<' '<<who.second<<'\n';
have[who.first][who.second]=1;
s.insert(who.first);
where[cur]=who;
}
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)
s.erase(lin);
}
}
return 0;
}
Compilation message
tram.cpp: In function 'int main()':
tram.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=1;i<v.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
492 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
18 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
428 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
17 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
864 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
19 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
824 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
23 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
852 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
1264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |