Submission #492902

# Submission time Handle Problem Language Result Execution time Memory
492902 2021-12-09T16:11:07 Z Biaz Coin Collecting (JOI19_ho_t4) C++17
8 / 100
1000 ms 332 KB
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<double,int>
#define ALL(i) i.begin(),i.end()
#define gcd(i,j) __gcd(i,j)
#define fi first
#define se second
#define eps 0.00000001
#define ist insert
#define DNE nullptr
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
int max(int x,int y){return x>=y?x:y;}
int min(int x,int y){return x>=y?y:x;}
using namespace std;
typedef int ll;
const int N=200005;
const int M=1000005;
const int MOD=1000000007;//998244353;
const int INF=1000000000000000000;//2147483647;

int n,ans;
pi p[N];
string bit;
int calc(){
    vector<pi> a(n),b(n);
    int ai=0,bi=0;
    for (int i=0;i<2*n;i++){
        if (bit[i]=='0')
            a[ai++]=p[i];
        else b[bi++]=p[i];
    }
    int sum=0;
    for (int i=0;i<ai;i++)
        sum+=abs(a[i].fi-(i+1))+abs(1-a[i].se);
    for (int i=0;i<ai;i++)
        sum+=abs(b[i].fi-(i+1))+abs(2-b[i].se);
    return sum;
}
inline void sol(){
    cin >>n;
    for (int i=0;i<2*n;i++)
        cin >>p[i].fi>>p[i].se;
    sort(p,p+2*n);
    for (int i=0;i<n;i++)
        bit+="0";
    for (int i=0;i<n;i++)
        bit+="1";
    ans=INF;
    do{
        ans=min(ans,calc());
    }while (next_permutation(ALL(bit)));
    cout <<ans<<'\n';
}

signed main(){
    Nanase_Kurumi_aka_menhera_chan_is_mine
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 41 ms 204 KB Output is correct
5 Correct 44 ms 296 KB Output is correct
6 Correct 42 ms 292 KB Output is correct
7 Correct 42 ms 204 KB Output is correct
8 Correct 43 ms 204 KB Output is correct
9 Correct 42 ms 300 KB Output is correct
10 Correct 43 ms 292 KB Output is correct
11 Correct 42 ms 296 KB Output is correct
12 Correct 41 ms 204 KB Output is correct
13 Correct 46 ms 296 KB Output is correct
14 Correct 44 ms 308 KB Output is correct
15 Correct 43 ms 204 KB Output is correct
16 Correct 47 ms 296 KB Output is correct
17 Correct 42 ms 204 KB Output is correct
18 Correct 42 ms 292 KB Output is correct
19 Correct 45 ms 292 KB Output is correct
20 Correct 42 ms 292 KB Output is correct
21 Correct 43 ms 204 KB Output is correct
22 Correct 44 ms 292 KB Output is correct
23 Correct 42 ms 204 KB Output is correct
24 Correct 42 ms 296 KB Output is correct
25 Correct 43 ms 204 KB Output is correct
26 Correct 46 ms 204 KB Output is correct
27 Correct 43 ms 204 KB Output is correct
28 Correct 42 ms 204 KB Output is correct
29 Correct 42 ms 304 KB Output is correct
30 Correct 42 ms 204 KB Output is correct
31 Correct 44 ms 304 KB Output is correct
32 Correct 41 ms 204 KB Output is correct
33 Correct 43 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 41 ms 204 KB Output is correct
5 Correct 44 ms 296 KB Output is correct
6 Correct 42 ms 292 KB Output is correct
7 Correct 42 ms 204 KB Output is correct
8 Correct 43 ms 204 KB Output is correct
9 Correct 42 ms 300 KB Output is correct
10 Correct 43 ms 292 KB Output is correct
11 Correct 42 ms 296 KB Output is correct
12 Correct 41 ms 204 KB Output is correct
13 Correct 46 ms 296 KB Output is correct
14 Correct 44 ms 308 KB Output is correct
15 Correct 43 ms 204 KB Output is correct
16 Correct 47 ms 296 KB Output is correct
17 Correct 42 ms 204 KB Output is correct
18 Correct 42 ms 292 KB Output is correct
19 Correct 45 ms 292 KB Output is correct
20 Correct 42 ms 292 KB Output is correct
21 Correct 43 ms 204 KB Output is correct
22 Correct 44 ms 292 KB Output is correct
23 Correct 42 ms 204 KB Output is correct
24 Correct 42 ms 296 KB Output is correct
25 Correct 43 ms 204 KB Output is correct
26 Correct 46 ms 204 KB Output is correct
27 Correct 43 ms 204 KB Output is correct
28 Correct 42 ms 204 KB Output is correct
29 Correct 42 ms 304 KB Output is correct
30 Correct 42 ms 204 KB Output is correct
31 Correct 44 ms 304 KB Output is correct
32 Correct 41 ms 204 KB Output is correct
33 Correct 43 ms 308 KB Output is correct
34 Execution timed out 1096 ms 332 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 41 ms 204 KB Output is correct
5 Correct 44 ms 296 KB Output is correct
6 Correct 42 ms 292 KB Output is correct
7 Correct 42 ms 204 KB Output is correct
8 Correct 43 ms 204 KB Output is correct
9 Correct 42 ms 300 KB Output is correct
10 Correct 43 ms 292 KB Output is correct
11 Correct 42 ms 296 KB Output is correct
12 Correct 41 ms 204 KB Output is correct
13 Correct 46 ms 296 KB Output is correct
14 Correct 44 ms 308 KB Output is correct
15 Correct 43 ms 204 KB Output is correct
16 Correct 47 ms 296 KB Output is correct
17 Correct 42 ms 204 KB Output is correct
18 Correct 42 ms 292 KB Output is correct
19 Correct 45 ms 292 KB Output is correct
20 Correct 42 ms 292 KB Output is correct
21 Correct 43 ms 204 KB Output is correct
22 Correct 44 ms 292 KB Output is correct
23 Correct 42 ms 204 KB Output is correct
24 Correct 42 ms 296 KB Output is correct
25 Correct 43 ms 204 KB Output is correct
26 Correct 46 ms 204 KB Output is correct
27 Correct 43 ms 204 KB Output is correct
28 Correct 42 ms 204 KB Output is correct
29 Correct 42 ms 304 KB Output is correct
30 Correct 42 ms 204 KB Output is correct
31 Correct 44 ms 304 KB Output is correct
32 Correct 41 ms 204 KB Output is correct
33 Correct 43 ms 308 KB Output is correct
34 Execution timed out 1096 ms 332 KB Time limit exceeded
35 Halted 0 ms 0 KB -