| Task: | Freshman's Database |
| Sender: | megachainmail |
| Submission time: | 2020-10-03 14:01:29 +0300 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | RUNTIME ERROR |
| test | verdict | time | |
|---|---|---|---|
| #1 | RUNTIME ERROR | 0.02 s | details |
| #2 | RUNTIME ERROR | 0.02 s | details |
| #3 | RUNTIME ERROR | 0.02 s | details |
| #4 | RUNTIME ERROR | 0.02 s | details |
| #5 | RUNTIME ERROR | 0.02 s | details |
| #6 | RUNTIME ERROR | 0.02 s | details |
| #7 | RUNTIME ERROR | 0.02 s | details |
| #8 | RUNTIME ERROR | 0.02 s | details |
| #9 | RUNTIME ERROR | 0.02 s | details |
| #10 | RUNTIME ERROR | 0.02 s | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("cases.txt", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~Code
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s;
int arr[1000000] = {0};
bool visited[1000000] = {false};
int main() {
freopen("cases.txt", "r", stdin);
std::ios::sync_with_stdio(false);
int n, r;
r = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
arr[i] = num - 1;
}
for (int i = 0; i < n; i++) {
if (visited[i] == false) {
int next = i;
int nextNext = i;
do {
next = arr[next];
nextNext = arr[arr[nextNext]];
} while ((next != nextNext));
if (visited[next] == false) {
r += 1;
}
int endPoint = next;
do {
visited[next] = true;
next = arr[next];
} while (next != endPoint && visited[next] == false);
}
}
cout << r << endl;
return 0;
}Test details
Test 1
Verdict: RUNTIME ERROR
| input |
|---|
| 16
2 3 4 5 6 1 4 7 7 4 12 11 14 1... |
| correct output |
|---|
| 3 |
| user output |
|---|
| (empty) |
Test 2
Verdict: RUNTIME ERROR
| input |
|---|
| 2
2 1 |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Test 3
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 906853 1 1 1 3 4 3 2 5 5 5 10 ... |
| correct output |
|---|
| 1 |
| user output |
|---|
| (empty) |
Test 4
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 227998 891986 290950 887622 37... |
| correct output |
|---|
| 6736 |
| user output |
|---|
| (empty) |
Test 5
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 832833 455297 341097 88590 258... |
| correct output |
|---|
| 16 |
| user output |
|---|
| (empty) |
Test 6
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 635299 635243 476863 88031 195... |
| correct output |
|---|
| 73 |
| user output |
|---|
| (empty) |
Test 7
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 444011 366349 710148 901981 81... |
| correct output |
|---|
| 244 |
| user output |
|---|
| (empty) |
Test 8
Verdict: RUNTIME ERROR
| input |
|---|
| 1000000 248398 271880 881725 521008 33... |
| correct output |
|---|
| 332 |
| user output |
|---|
| (empty) |
Test 9
Verdict: RUNTIME ERROR
| input |
|---|
| 999999 938280 731633 536902 381480 65... |
| correct output |
|---|
| 6771 |
| user output |
|---|
| (empty) |
Test 10
Verdict: RUNTIME ERROR
| input |
|---|
| 999999 196127 288846 245904 406819 13... |
| correct output |
|---|
| 105 |
| user output |
|---|
| (empty) |
