Submission #101961

# Submission time Handle Problem Language Result Execution time Memory
101961 2019-03-21T07:45:47 Z tim25871014 Wiring (IOI17_wiring) C++17
20 / 100
50 ms 2176 KB
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;

long long min_total_length(vector<int> r, vector<int> b){
    int n=r.size(),m=b.size();
    int minn=min(n,m);
    
    if(n<=200 && m<=200){
        
        int dp[210][210];
        dp[0][0]=abs(r[0]-b[0]);
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++){
                int minn=2147483647;
                if(i&&j) minn=min(minn,dp[i-1][j-1]);
                if(i) minn=min(minn,dp[i-1][j]);
                if(j) minn=min(minn,dp[i][j-1]);
                
                minn+=abs(r[i]-b[j]);
                
                if(i||j) dp[i][j]=minn;
            }
        return dp[n-1][m-1];
    }
    
    long long ans=0;
    for(int i=0;i<minn;i++)
        ans+=b[m-i-1]-r[i];
    
    for(int i=minn;i<n;i++)
        ans+=b[0]-r[i];
    
    for(int i=minn;i<m;i++)
        ans+=b[m-i-1]-r[n-1];
    
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 560 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 26 ms 1472 KB Output is correct
4 Correct 26 ms 1656 KB Output is correct
5 Correct 46 ms 1784 KB Output is correct
6 Correct 48 ms 2040 KB Output is correct
7 Correct 38 ms 2172 KB Output is correct
8 Correct 32 ms 2176 KB Output is correct
9 Correct 50 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 31 ms 1884 KB 3rd lines differ - on the 1st token, expected: '1068938599', found: '-303948787415'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 24 ms 1912 KB 3rd lines differ - on the 1st token, expected: '373710605', found: '2074975518'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 560 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 3 ms 484 KB Output is correct
19 Correct 26 ms 1472 KB Output is correct
20 Correct 26 ms 1656 KB Output is correct
21 Correct 46 ms 1784 KB Output is correct
22 Correct 48 ms 2040 KB Output is correct
23 Correct 38 ms 2172 KB Output is correct
24 Correct 32 ms 2176 KB Output is correct
25 Correct 50 ms 2172 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Incorrect 31 ms 1884 KB 3rd lines differ - on the 1st token, expected: '1068938599', found: '-303948787415'
29 Halted 0 ms 0 KB -