CSES - Putka Open 2015 – 4/6 - Results
Submission details
Task:Taulukot
Sender:Henrik Lievonen
Submission time:2015-10-10 10:43:22 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED26
#2ACCEPTED29
#3ACCEPTED45
Test results
testverdicttimegroup
#1ACCEPTED0.06 s1details
#2ACCEPTED0.06 s1details
#3ACCEPTED0.06 s1details
#4ACCEPTED0.06 s1details
#5ACCEPTED0.05 s1details
#6ACCEPTED0.05 s2details
#7ACCEPTED0.06 s2details
#8ACCEPTED0.05 s2details
#9ACCEPTED0.05 s2details
#10ACCEPTED0.06 s2details
#11ACCEPTED0.09 s3details
#12ACCEPTED0.08 s3details
#13ACCEPTED0.08 s3details
#14ACCEPTED0.09 s3details
#15ACCEPTED0.09 s3details

Compiler report

input/code.cpp: In function 'void createPrimes()':
input/code.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 2; i < primetable.size(); i++) {
                    ^
input/code.cpp:48:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = i; j < primetable.size(); j += i)
                      ^

Code

#include <iostream>
#include <set>
#include <vector>
using namespace std;
// 1
// 1
// 1 2
// 2 1
//6
// 1 2 3
// 1 3 2
//12
// 1 2 3 4
// 4 3 2 1
//20
// 1 2 3 4 5
// 1 5 4 3 2
//30
// 1 2 3 4 5 6
// 4 3 2 1 6 5
// 6 5 4 3 2 1
//42
// 1 2 3 4 5 6 7
// 1 5 4 3 2 7 6
// 1 3 2 7 6 5 4
//56
// 1 2 3 4 5 6 7 8
// 4 3 2 1 8 7 6 5
// 8 3
// 72
set<int> primes;
void createPrimes() {
vector<bool> primetable(200100);
for (int i = 2; i < primetable.size(); i++) {
if (!primetable[i]) {
primes.insert(i);
for (int j = i; j < primetable.size(); j += i)
primetable[j] = true;
}
}
}
int main() {
createPrimes();
int n;
cin >> n;
set<int> l;
for (int i = 1; i <= n; i++)
l.insert(i);
vector<int> res(n + 1);
for (int i = n; i >= 1; i--) {
if (!l.count(i))
continue;
int testsum = i + *l.rbegin();
auto it = primes.lower_bound(testsum);
if (*it > testsum) it--;
int p = *it;
int o = p - i;
if (res[0]) {
cerr << "ERR";
}
res[i] = o;
res[o] = i;
l.erase(i);
l.erase(o);
//l.erase(i);
}
for (int i = 1; i <= n; i++)
cout << i << " ";
cout << "\n";
for (int i = 1; i <= n; i++)
cout << res[i] << " ";
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1

correct output


user output


Test 2

Group: 1

Verdict: ACCEPTED

input
4

correct output
1 2 3 4 
2 1 4 3 

user output
1 2 3 4 
2 1 4 3 

Test 3

Group: 1

Verdict: ACCEPTED

input
5

correct output
1 2 3 4 5 
1 5 4 3 2 

user output
1 2 3 4 5 
1 5 4 3 2 

Test 4

Group: 1

Verdict: ACCEPTED

input
8

correct output
1 2 3 4 5 6 7 8 
2 1 4 3 8 7 6 5 

user output
1 2 3 4 5 6 7 8 
2 1 4 3 8 7 6 5 

Test 5

Group: 1

Verdict: ACCEPTED

input
9

correct output
1 2 3 4 5 6 7 8 9 
1 5 4 3 2 7 6 9 8 

user output
1 2 3 4 5 6 7 8 9 
1 5 4 3 2 7 6 9 8 

Test 6

Group: 2

Verdict: ACCEPTED

input
77

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 7

Group: 2

Verdict: ACCEPTED

input
70

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 8

Group: 2

Verdict: ACCEPTED

input
72

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 9

Group: 2

Verdict: ACCEPTED

input
86

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 10

Group: 2

Verdict: ACCEPTED

input
68

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 11

Group: 3

Verdict: ACCEPTED

input
90764

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 12

Group: 3

Verdict: ACCEPTED

input
97976

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 13

Group: 3

Verdict: ACCEPTED

input
96762

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 14

Group: 3

Verdict: ACCEPTED

input
94823

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 15

Group: 3

Verdict: ACCEPTED

input
91479

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...