Task: | Taulukot |
Sender: | |
Submission time: | 2015-10-10 19:19:19 +0300 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 26 |
#2 | ACCEPTED | 29 |
#3 | ACCEPTED | 45 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.05 s | 1 | details |
#2 | ACCEPTED | 0.05 s | 1 | details |
#3 | ACCEPTED | 0.05 s | 1 | details |
#4 | ACCEPTED | 0.07 s | 1 | details |
#5 | ACCEPTED | 0.06 s | 1 | details |
#6 | ACCEPTED | 0.05 s | 2 | details |
#7 | ACCEPTED | 0.06 s | 2 | details |
#8 | ACCEPTED | 0.06 s | 2 | details |
#9 | ACCEPTED | 0.05 s | 2 | details |
#10 | ACCEPTED | 0.05 s | 2 | details |
#11 | ACCEPTED | 0.06 s | 3 | details |
#12 | ACCEPTED | 0.05 s | 3 | details |
#13 | ACCEPTED | 0.06 s | 3 | details |
#14 | ACCEPTED | 0.06 s | 3 | details |
#15 | ACCEPTED | 0.05 s | 3 | details |
Code
#include <iostream> #include <set> #include <vector> #include <cmath> using namespace std; typedef long long LL; // Returns an array isPrime of length n+1 such that isPrime[x] = 1 if x is prime and 0 else char* eratosthenes(int n){ int m = (int) sqrt(n) + 1; char* isPrime = (char*)malloc((n+1)*sizeof(char)); for(int i = 0; i <= n; i++) isPrime[i] = (i <= 1) ? 0 : 1; for(int i = 2; i <= m; i++) if(isPrime[i]) for (int j = 2*i; j <= n; j += i) isPrime[j] = 0; return isPrime; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; char* is_prime = eratosthenes(2*n+100); vector<int> ans(n+1,-1); int x = n; for(int i = n; i >= 1; i--){ if(is_prime[i + x]){ int j = i; while(j <= n && ans[j] == -1){ ans[j] = x; x--; j++; } } } for(int i = 1; i <= n; i++){ cout << i << " "; } cout << endl; for(int i = 1; i <= n; i++){ cout << ans[i] << " "; } cout << endl; }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
1 |
correct output |
---|
1 1 |
user output |
---|
1 1 |
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 ... |