QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625224 | #5426. Drain the Water Tank | Zaoly | WA | 1ms | 3844kb | C++20 | 3.7kb | 2024-10-09 18:02:40 | 2024-10-09 18:02:41 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
using ll = long long;
using ld = long double;
using namespace std;
bool turnleft(pair<ll, ll> p1, pair<ll, ll> p2, pair<ll, ll> p3){
auto [x1, y1] = p1;
auto [x2, y2] = p2;
auto [x3, y3] = p3;
ll xa = 0, ya = 0, xb = 0, yb = 0;
xa = x2 - x1;
ya = y2 - y1;
xb = x3 - x2;
yb = y3 - y2;
return xa * yb - xb * ya >= 0;
}
//
//void solve(){
// int n;
// cin >> n;
//
// vector<pair<int, int> > a(n + 1);
// for (int i = 0; i < n; i++){
// cin >> a[i].first >> a[i].second;
// }
// int st=0;
// for(int i=0;i<n;i++){
// if(a[i].second>a[st].second){
// st=i;
// //break;
// }
// }
// vector<pair<int, int> > point;
// point.push_back({a[st]});
// point.push_back({a[(st+1)%n]});
// for (int j = 2; j < n; j++){
// int i=(j+st)%n;
// if (a[i].second >= point.back().second && point[point.size() - 1].second >= point[point.size() - 2].second&&a[i].first >= point.back().first && point[point.size() - 1].first >= point[point.size() - 2].first){
// point.back() = a[i];
// continue;
// }
// else{
// point.push_back({a[i]});
// }
// }
//
//// cout << "point:" << endl;
//// for (auto i: point){
//// cout << i.first << " " << i.second << endl;
//// }
// int si = point.size();
// int ans = 0;
// for (int i = 0; i < si; i++){
// int pr = (i - 1 + si) % si;
// int ne = (i + 1) % si;
//
// if (point[i].second <= point[pr].second && point[i].second < point[ne].second &&
// turnleft(point[pr], point[i], point[ne])){
// //cout << i << endl;
// ans++;
// }
// }
// cout << ans << endl;
//}
void solve() {
vector <pair <ll,ll>> point;
ll n;cin>>n;
vector <pair <ll,ll>> p(n+5);
for(ll i=3;i<=n+2;i++) {
cin>>p[i].first>>p[i].second;
}
p[1]=p[n+1];
p[2]=p[n+2];
p[n+3]=p[3];
p[n+4]=p[4];
for(ll i=1;i<=n+4;i++) {
ll j=i+1;
for(;j<=n+4;j++) {
if(p[j].second!=p[i].second) break;
}
point.push_back(p[i]);
if(j!=i+1) point.push_back(p[j-1]);
i=j-1;
}
vector <pair <ll,ll>> check_point;
check_point.push_back({0,0});
for(auto t:point) check_point.push_back(t);
auto check_min=[&](ll left,ll right)->bool {
if(check_point[left].second == check_point[right].second) {
return (check_point[left-1].second>check_point[left].second && check_point[right+1].second >check_point[right].second);
}return false;
};
ll ans=0;
for(ll i=3;i<=2+n;i++) {
if(check_min(i,i+1) && turnleft(check_point[i-1],check_point[i],check_point[i+2])) {
ans++;
//cout<<"be_chosen_point:: "<<check_point[i].first<<' '<<check_point[i].second<<endl;
}
}
for(ll i=3;i<=2+n;i++) {
if(check_point[i-1].second>check_point[i].second && check_point[i+1].second > check_point[i].second
&&turnleft(check_point[i-1],check_point[i],check_point[i+1])
) {
//cout<<"i::"<<i<<endl;
//cout<<"be_chosen_point:: "<<check_point[i].first<<' '<<check_point[i].second<<endl;
ans++;
}
}
//cout<<"Get"<<endl;
for(auto t:check_point) {
//cout<<t.first<<' '<<t.second<<endl;
}
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int ttt = 1;
//cin >> ttt;
while (ttt--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
6 0 0 1 1 2 1 3 0 3 2 0 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
8 4 4 0 4 0 2 1 2 2 2 2 0 3 0 4 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
7 1 0 3 4 0 3 1 2 2 3 1 1 0 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
6 0 0 2 0 1 1 4 1 5 0 3 4
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
8 0 0 1 0 3 -1 3 0 1 1 4 1 5 0 3 4
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
5 0 0 170 0 140 30 60 30 0 70
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
5 0 0 170 0 140 30 60 30 0 100
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
5 0 0 1 2 1 5 0 2 0 1
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 0 0 100 0 0 100
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
3 200 0 100 100 0 0
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
3 50 50 100 50 100 100
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
3 3 0 0 4 0 0
output:
1
result:
ok 1 number(s): "1"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
3 10000 10000 -10000 10000 10000 9999
output:
1
result:
ok 1 number(s): "1"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
3 10000 10000 -10000 10000 10000 9900
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 10000 10000 9999 10000 10000 -10000
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
3 0 0 200 0 100 173
output:
1
result:
ok 1 number(s): "1"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 0 0 200 0 100 1
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 -10000 -10000 10000 9999 9999 10000
output:
1
result:
ok 1 number(s): "1"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
4 10 10 20 10 20 20 10 20
output:
1
result:
ok 1 number(s): "1"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
4 -10000 -10000 10000 -10000 10000 10000 -10000 10000
output:
1
result:
ok 1 number(s): "1"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
4 100 0 200 100 100 200 0 100
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
4 0 1 100 0 101 100 1 101
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
4 0 0 100 0 100 50 0 50
output:
1
result:
ok 1 number(s): "1"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
4 0 0 50 0 50 100 0 100
output:
1
result:
ok 1 number(s): "1"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
4 0 10 10 0 100 90 90 100
output:
1
result:
ok 1 number(s): "1"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
8 0 100 100 0 250 0 350 100 350 250 250 350 100 350 0 250
output:
1
result:
ok 1 number(s): "1"
Test #27:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
6 0 50 10 0 70 0 80 10 70 50 50 80
output:
1
result:
ok 1 number(s): "1"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
4 0 100 0 0 100 0 20 20
output:
1
result:
ok 1 number(s): "1"
Test #29:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
4 0 100 55 55 100 0 100 100
output:
1
result:
ok 1 number(s): "1"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
8 0 0 100 0 100 20 40 20 40 40 100 40 100 60 0 60
output:
1
result:
ok 1 number(s): "1"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
12 0 0 90 0 90 30 40 30 40 40 90 40 90 50 0 50 0 20 50 20 50 10 0 10
output:
1
result:
ok 1 number(s): "1"
Test #32:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
12 0 0 100 0 100 100 10 100 10 110 200 110 200 60 101 60 101 40 210 40 210 120 0 120
output:
2
result:
ok 1 number(s): "2"
Test #33:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
10 1000 0 1100 0 1200 100 1220 200 1200 110 1100 10 1000 10 900 110 880 200 900 100
output:
1
result:
ok 1 number(s): "1"
Test #34:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
16 0 0 60 0 60 70 0 70 0 20 40 20 40 50 20 50 20 40 30 40 30 30 10 30 10 60 50 60 50 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #35:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
8 0 1 100 0 5 5 200 5 105 0 205 1 205 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #36:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
8 0 1 50 0 5 5 200 5 150 0 205 1 205 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #37:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
9 99 100 100 100 99 99 301 99 300 100 301 100 201 274 200 273 199 274
output:
1
result:
ok 1 number(s): "1"
Test #38:
score: -100
Wrong Answer
time: 0ms
memory: 3836kb
input:
15 0 0 10 0 20 0 30 0 40 0 50 0 40 10 30 20 20 30 10 40 0 50 0 40 0 30 0 20 0 10
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'