#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
#define pii pair<int,int>
#define fi first
#define se second
const ll MOD=1e9+7;
void solve(){
int n;
cin >> n;
int ans=0;
ll robot[n];
ll building[n];
bool subtask2=true;
priority_queue<pii, vector<pii>, greater<pii> > order;
for(int i=0; i<n; i++){
cin >> robot[i];
}
for(int i=0; i<n; i++){
cin >> building[i];
order.push(make_pair(building[i],i));
if(subtask2 && i>0){
if(building[i]!=building[i-1]){
subtask2=false;
}
}
}
if(subtask2){
bool visited[n];
memset(visited,0,sizeof(visited));
for(int i=0; i<n; i++){
if(robot[i]==building[i] && !visited[i]){
visited[i]=true;
ans++;
ll idx=i+1;
while(robot[idx]<=robot[i] && idx<n){
visited[idx]=true;
ans++;
idx++;
}
idx=i-1;
while(robot[idx]<=robot[i] && idx>=0){
visited[idx]=true;
ans++;
idx--;
}
}
}
}else{
bool bisa[n];
memset(bisa,0,sizeof(bisa));
for(int i=0; i<n; i++){
int cur=order.top().se;
order.pop();
ll idx=cur;
ll debt=0;
ll nambah=0;
bool ada=false;
while(robot[idx]<=building[cur] && idx<n){
if(building[idx]==building[cur]){
nambah++;
}
if(robot[idx]==building[cur]){
ada=true;
break;
}
if(bisa[idx]){
debt++;
}
idx++;
}
if(ada){
if(nambah>debt){
for(int j=cur; j<=idx; j++){
robot[j]=building[cur];
if(robot[j]==building[j]){
bisa[j]=true;
}else{
bisa[j]=false;
}
}
}
}
debt=0;
nambah=0;
if(ada){
idx=cur-1;
}else{
idx=cur;
}
ada=false;
while(robot[idx]<=building[cur] && idx>=0){
if(building[idx]==building[cur]){
nambah++;
}
if(robot[idx]==building[cur]){
ada=true;
break;
}
if(bisa[idx]){
debt++;
}
idx--;
}
if(ada){
if(nambah>debt){
for(int j=cur; j>=idx; j--){
robot[j]=building[cur];
if(robot[j]==building[j]){
bisa[j]=true;
}else{
bisa[j]=false;
}
}
}
}
}
for(int j=0; j<n; j++){
if(robot[j]==building[j]){
ans++;
}
}
}
cout << ans << endl;
return;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int q=1;
for(int i=0; i<q; i++){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
3 |
Correct |
12 ms |
2876 KB |
Output is correct |
4 |
Correct |
10 ms |
3028 KB |
Output is correct |
5 |
Correct |
18 ms |
3028 KB |
Output is correct |
6 |
Correct |
10 ms |
3028 KB |
Output is correct |
7 |
Correct |
11 ms |
3028 KB |
Output is correct |
8 |
Correct |
18 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
14 ms |
2268 KB |
Output is correct |
3 |
Correct |
30 ms |
4180 KB |
Output is correct |
4 |
Correct |
35 ms |
4760 KB |
Output is correct |
5 |
Execution timed out |
1073 ms |
4812 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |