Submission #89382

# Submission time Handle Problem Language Result Execution time Memory
89382 2018-12-12T18:29:04 Z alipasha Studentsko (COCI14_studentsko) C++14
10 / 100
7 ms 2612 KB
#include<bits/stdc++.h>

using namespace std;

int test;
int n;
int k;
int dp[1005][2];
int ps[1005][1005];
int f[1005][2];
int A[1005];
pair<int,int> B[1005];
int main(){
    cin >> n;
    cin >> k;
    memset(f,-1,sizeof f);
    for(int i=0; i<n; i++)
    {
        int v;
        cin >> v;
        B[i]={v,i};
    }
    sort(B,B+n);
    int group=0;
    int cnt=0;
    for(int i=0; i<n; i++)
    {
        A[B[i].second]=group;
        cnt++;
        if(cnt==k)
        {
            cnt=0;
            group++;
        }
    }
    ps[0][A[0]]++;
    f[A[0]][0]=0;
    f[A[0]][1]=0;
    for(int i=1; i<n; i++)
    {
        for(int j=0; j<n/k; j++)
        {
            ps[i][j]=ps[i-1][j];
        }
        ps[i][A[i]]++;
        if(f[A[i]][0]==-1)
        {
            f[A[i]][0]=i;
            f[A[i]][1]=i;
        }
        else
        {
            f[A[i]][1]=i;
        }
    }
    int ans=0;
    for(int i=0; i<n/k-1; i++)
    {
        int start=f[i+1][0];//avalin i+1;
        int end=f[i][1];// akharin i;
        //ps[end][i]= bad az avalin i+1 chand i oomade
        //ps[n][i]-ps[start][i]
        ans+=min(ps[end][i+1],ps[n-1][i]-ps[start][i]);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 440 KB Output is correct
2 Incorrect 2 ms 460 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1528 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1528 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 1528 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 2484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 2612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 2612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 2612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -