Submission #22993

# Submission time Handle Problem Language Result Execution time Memory
22993 2017-05-01T03:02:44 Z model_code Hacker (BOI15_hac) C++11
20 / 100
1000 ms 1312 KB
/*
    Task: Hacker
    Slow solution 2
    Author: Krzysztof Kiljan
    Complexity: O(n^3)

    Brutal simulation, for every start S we brutally calculate what would be the result
    if second player started in any of the remaining points. For every point, we also brutally
    calculate the sum of the points in it.
 */

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>

using namespace std;

#define REP(I,N) for(int I=0;I<(N);I++)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second


typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

const int MAXN = 500013;
VI v;

int n, m, k, operCompNum, sumAll;

void readInput()
{
    sumAll = 0;
    scanf("%d", &n);

    operCompNum = n / 2;

    REP(i, n)
    {
        scanf("%d", &k);
        v.PB(k);
        sumAll += k;
    }
}

//makes   v -> vv, for easier further implementation

void duplicateV()
{
    REP(i, n)
    v.push_back(v[i]);
}


//Calculates the sum from computers protectected by operator if started at "start" position
int calcOperProtection(int start)
{
    int sum = 0;

    for (int i = start; i < start + operCompNum; i++)
        sum += v[i];

    return sum;
}

// Calculates the value hacker will get assuming he will start at computer number nr
// Numbers in <0, n)

int tryStart(int nr)
{
    int res = 0;

    for (int i = 1; i <= n - operCompNum; i++)
        res = max(res, calcOperProtection(i + nr));

    return sumAll - res;
}

int solve()
{
    int ans = 0;

    REP(i, n)
    ans = max(ans, tryStart(i));

    return ans;
}

int main()
{
    readInput();
    duplicateV();
    int ans = solve();
    printf("%d\n", ans);
    return 0;
}

Compilation message

hac.cpp: In function 'void readInput()':
hac.cpp:38:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
hac.cpp:44:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &k);
                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1172 KB Output is correct
2 Correct 0 ms 1172 KB Output is correct
3 Correct 0 ms 1172 KB Output is correct
4 Correct 0 ms 1172 KB Output is correct
5 Correct 0 ms 1172 KB Output is correct
6 Correct 0 ms 1172 KB Output is correct
7 Correct 3 ms 1172 KB Output is correct
8 Correct 3 ms 1172 KB Output is correct
9 Correct 3 ms 1172 KB Output is correct
10 Correct 3 ms 1172 KB Output is correct
11 Correct 3 ms 1172 KB Output is correct
12 Correct 3 ms 1172 KB Output is correct
13 Correct 0 ms 1172 KB Output is correct
14 Correct 0 ms 1172 KB Output is correct
15 Correct 0 ms 1172 KB Output is correct
16 Correct 3 ms 1172 KB Output is correct
17 Correct 3 ms 1172 KB Output is correct
18 Correct 3 ms 1172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1172 KB Output is correct
2 Correct 0 ms 1172 KB Output is correct
3 Correct 0 ms 1172 KB Output is correct
4 Correct 0 ms 1172 KB Output is correct
5 Correct 0 ms 1172 KB Output is correct
6 Correct 0 ms 1172 KB Output is correct
7 Correct 3 ms 1172 KB Output is correct
8 Correct 3 ms 1172 KB Output is correct
9 Correct 3 ms 1172 KB Output is correct
10 Correct 3 ms 1172 KB Output is correct
11 Correct 3 ms 1172 KB Output is correct
12 Correct 3 ms 1172 KB Output is correct
13 Correct 0 ms 1172 KB Output is correct
14 Correct 0 ms 1172 KB Output is correct
15 Correct 0 ms 1172 KB Output is correct
16 Correct 3 ms 1172 KB Output is correct
17 Correct 3 ms 1172 KB Output is correct
18 Correct 3 ms 1172 KB Output is correct
19 Correct 16 ms 1172 KB Output is correct
20 Correct 146 ms 1172 KB Output is correct
21 Correct 63 ms 1172 KB Output is correct
22 Execution timed out 1000 ms 1312 KB Execution timed out
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1172 KB Output is correct
2 Correct 9 ms 1172 KB Output is correct
3 Execution timed out 1000 ms 1312 KB Execution timed out
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1172 KB Output is correct
2 Correct 0 ms 1172 KB Output is correct
3 Correct 0 ms 1172 KB Output is correct
4 Correct 0 ms 1172 KB Output is correct
5 Correct 0 ms 1172 KB Output is correct
6 Correct 0 ms 1172 KB Output is correct
7 Correct 3 ms 1172 KB Output is correct
8 Correct 3 ms 1172 KB Output is correct
9 Correct 3 ms 1172 KB Output is correct
10 Correct 3 ms 1172 KB Output is correct
11 Correct 3 ms 1172 KB Output is correct
12 Correct 3 ms 1172 KB Output is correct
13 Correct 0 ms 1172 KB Output is correct
14 Correct 0 ms 1172 KB Output is correct
15 Correct 0 ms 1172 KB Output is correct
16 Correct 3 ms 1172 KB Output is correct
17 Correct 3 ms 1172 KB Output is correct
18 Correct 3 ms 1172 KB Output is correct
19 Correct 16 ms 1172 KB Output is correct
20 Correct 146 ms 1172 KB Output is correct
21 Correct 63 ms 1172 KB Output is correct
22 Execution timed out 1000 ms 1312 KB Execution timed out
23 Halted 0 ms 0 KB -