Submission #966584

# Submission time Handle Problem Language Result Execution time Memory
966584 2024-04-20T05:34:56 Z Amr Wiring (IOI17_wiring) C++17
0 / 100
1 ms 348 KB
#include "wiring.h"
#include<bits/stdc++.h>
using namespace std;
#define sz size()
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int N = 2e5+2;
ll a[N];
long long min_total_length(std::vector<int> r, std::vector<int> b) {
    ll n = r.sz, m = b.sz;
    for(int i = 0; i < n; i++) a[r[i]] = 1;
    for(int i = 0; i < m; i++) a[b[i]] = 0;
    ll newlst = 0,start = 1,ans=0;
    for(int i = 1; i <= m+n; i++)
    {
        if(i==m+n||a[i+1]!=a[i])
        {
            ll en = i;
            for(int j = start; j <= en; j++)
            {
                ll lst = newlst; newlst = 0;
                ll d1 = j-start , d2 = en-j;
                if((start!=1)&&lst>0&&(d1<d2||en==n+m))
                {
                    lst--;
                    ans+=d1;
                }
                else if((start!=1)&&lst==0&&(d1+1<d2||en==n+m))
                {
                    ans+=d1+1;
                }
                else
                {
                    newlst++;
                    ans+=d2+1;
                }
            }
          //  cout << ans << " ";
            start = i+1;
        }
    }
    return ans;

}
//b rrr bb r bb
//1 + 2 + 1 + 1 + 1 + 2


// cases
//not start! lst > 0 and (d1<d2 or end)
//else notstart! lst == 0 (d1+1<D2 or end)
//else newlst++;

//cases:
//d1<d2
//d1+1<d2
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '253'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '904', found: '29'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '316', found: '36'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '27', found: '31'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '25859', found: '253'
2 Halted 0 ms 0 KB -