Submission
Status:
(PPPPPPPPPPPPPPP)(PPPPPPPP)(PPPPPPPPPP)(PPPPPPPPPP)(PPPPPPPPPP)(PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP)
Subtask/Task Score:
{3/3}{7/7}{12/12}{17/17}{21/21}{40/40}
Score: 100
User: 12345678
Problemset: รถไฟตู้เสบียง (Dining Car)
Language: cpp
Time: 0.002 second
Submitted On: 2026-02-13 10:26:48
#include <bits/stdc++.h>
#include "dining_car.h"
using namespace std;
int a, b;
int findinside(int l, int r)
{
while (l<r)
{
int md=(l+r)/2;
if (compare_cars(md, md+1)==-1) r=md;
else l=md+1;
}
return l;
}
pair<int, int> locate_dining_cars(int N)
{
int l=1, r=N;
while (l<r)
{
int md=(l+r)/2; // the left side is abit smaller
int side_query=compare_cars(l, r);
if (side_query==0)
{
a=findinside(l, md);
b=r-(a-l);
return {a, b};
}
int mid_query=compare_cars(md, md+1);
if (side_query==-1&&mid_query==-1) r=md;
else if (side_query==1&&mid_query==1) l=md+1;
else return {findinside(l, md), findinside(md+1, r)};
}
return {l ,l};
}