CSES - Datatähti 2017 alku - Results
Submission details
Task:Bittijono
Sender:ollpu
Submission time:2016-10-05 08:53:08 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.06 s1details
#2--2details
#3--3details

Code

#include <iostream>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long t[n], asd[n][2][2];
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
  }
  long p1 = 0, p2 = 0;
  for (int i = n-1; i >= 0; --i) {
    if ((i+1)%2) {
      p1 = max(p1, t[i]);
    } else {
      p2 = max(p2, t[i]);
    }
    asd[i][0][0] = p1;
    asd[i][0][1] = p2;
  }
  p1 = 0, p2 = 0;
  for (int i = 0; i < n; ++i) {
    if (i%2) {
      p2 = max(p2, t[i]);
    } else {
      p1 = max(p1, t[i]);
    }
    asd[i][1][0] = p1;
    asd[i][1][1] = p2;
  }
  long sum = asd[0][0][0]+asd[0][0][1];
  int m2i = -1;
  for (int i = 1; i < n-1; ++i) {
    long val = t[i] + max(asd[i-1][1][0], asd[i+1][0][1]) + max(asd[i-1][1][1], asd[i+1][0][0]);
    if (val < sum) sum = val, m2i = i;
  }
  int m3i = -1, m3j = -1;
  for (int i = 1; i < n-3; ++i) {
    for (int j = i+2; j < n-1; ++j) {
      long p1 = 0, p2 = 0, inv = 0, val = 0;
      for (int k = 0; k < n; ++k) {
        if (k == i || k == j) {
          val += t[k];
          inv++;
        } else if ((k+inv)%2) {
          p1 = max(p1, t[k]);
        } else {
          p2 = max(p2, t[k]);
        }
      }
      val += p1 + p2;
      if (val < sum) sum = val, m3i = i, m3j = j;
    }
  }
  if (m3i != -1) {
    cout << sum << ' ' << 3 << endl;
    for (int i = 0; i < n; ++i) {
      if (i < m3i) {
        cout << i%2+1;
      } else if (i == m3i) {
        cout << 3;
      } else if (i < m3j) {
        cout << (i+1)%2+1;
      } else if (i == m3j) {
        cout << 3;
      } else {
        cout << i%2+1 << ' ';
      }
      cout << ' ';
    }
  } else if (m2i == -1) {
    cout << sum << ' ' << 2 << endl;
    for (int i = 0; i < n; ++i) {
      cout << i%2+1 << ' ';
    }
  } else {
    cout << sum << ' ' << 3 << endl;
    for (int i = 0; i < n; ++i) {
      if (i < m2i) {
        cout << i%2+1 << ' ';
      } else if (i > m2i) {
        cout << (i+1)%2+1 << ' ';
      } else cout << "3 ";
    }
  }
  cout << endl;
}

Test details

Test 1

Group: 1

Verdict:

input
100
62
9
12
73
...

correct output
1
1
1
0
1
...

user output
200 2
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ...

Test 2

Group: 2

Verdict:

input
100000
565433
141881
120108
825392
...

correct output
1
1
0
0
1
...

user output
(empty)

Test 3

Group: 3

Verdict:

input
100000
374768524402011755
937067109466254318
389256426086302899
932585725667010169
...

correct output
0
1
1
1
1
...

user output
(empty)