QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109541#1441. Special GameKostlinWA 2ms3792kbC++141.3kb2023-05-29 17:08:112023-05-29 17:08:14

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-29 17:08:14]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3792kb
  • [2023-05-29 17:08:11]
  • Submitted

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define fi first
#define sc second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
#define pli pair<ll,int>
const int N=1005,oo=1e9;
inline int read() {
    int x=0,flag=0;char ch=getchar();
    while(ch<'0'||ch>'9') {flag|=(ch=='-');ch=getchar();}
    while('0'<=ch&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return flag?-x:x;
}
inline int mx(int x,int y) {return x>y?x:y;}
inline int mn(int x,int y) {return x<y?x:y;}
inline void swp(int &x,int &y) {x^=y^=x^=y;}
inline int as(int x) {return x>0?x:-x;}

int n,a[N],b[N];
int solve(int op,int l,int r,int L,int R) {
    if(l>r||L>R) return 0;
    if(a[l]>b[R]) return mn(r-l+1,R-L+1);
    if(b[L]>a[r]) return 0;
    if(op==1) { int ans=0;
        while(l<=r&&a[r]>b[R]) --r,++ans;
        if(l>r) return ans;
        return ans+=solve(2,l+1,r,L+1,R);
    } else {
        while(L<=R&&b[R]>a[r]) --R;
        if(L>R) return 0;
        return solve(1,l+1,r,L+1,R)+1;
    }
}
int main() {
    n=read();
    for(int i=1;i<=n;++i) a[i]=read();
    for(int i=1;i<=n;++i) b[i]=read();
    sort(a+1,a+n+1); sort(b+1,b+n+1);
    printf("%d\n",solve(1,1,n,1,n));
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3740kb

input:

3
1 2 5
3 4 6

output:

1

result:

ok "1"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3736kb

input:

2
4 3
1 2

output:

2

result:

ok "2"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3792kb

input:

1
1
2

output:

0

result:

ok "0"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3612kb

input:

9
2 12 10 3 4 7 17 14 16
6 1 13 11 9 15 18 8 5

output:

6

result:

wrong answer 1st words differ - expected: '5', found: '6'