답안 #711742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711742 2023-03-17T11:54:54 Z stevancv Brunhilda’s Birthday (BOI13_brunhilda) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int M = 1e5 + 2;
const int inf = 2e9;
vector<int> primes[M];
int idx[M], ans[N], koji[M], dp[M];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    multiset<pair<int, int>> s;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        assert(s.find({0, x}) == s.end());
        s.insert({0, x});
        for (int j = x; j < M; j += x) primes[j].push_back(x);
    }
    for (int i = 1; i <= q; i++) {
        int x; cin >> x;
        idx[x] = i;
    }
    for (int i = 1; i < M; i++) {
        dp[i] = inf;
        for (int j : primes[i]) {
            s.erase({koji[j], j});
        }
        if (!s.empty()) dp[i] = s.begin()->first + 1;
        if (idx[i] != 0) ans[idx[i]] = dp[i];
        for (int j : primes[i]) {
            s.insert({dp[i], j});
            koji[j] = dp[i];
        }
    }
    for (int i = 1; i <= q; i++) {
        if (ans[i] == inf) cout << "oo" << en;
        else cout << ans[i] << en;
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int M = 1e5 + 2;
const int inf = 2e9;
vector<int> primes[M];
int idx[M], ans[N], koji[M], dp[M];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    multiset<pair<int, int>> s;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        assert(s.find({0, x}) == s.end());
        s.insert({0, x});
        for (int j = x; j < M; j += x) primes[j].push_back(x);
    }
    for (int i = 1; i <= q; i++) {
        int x; cin >> x;
        idx[x] = i;
    }
    for (int i = 1; i < M; i++) {
        dp[i] = inf;
        for (int j : primes[i]) {
            s.erase({koji[j], j});
        }
        if (!s.empty()) dp[i] = s.begin()->first + 1;
        if (idx[i] != 0) ans[idx[i]] = dp[i];
        for (int j : primes[i]) {
            s.insert({dp[i], j});
            koji[j] = dp[i];
        }
    }
    for (int i = 1; i <= q; i++) {
        if (ans[i] == inf) cout << "oo" << en;
        else cout << ans[i] << en;
    }
    return 0;
}

Compilation message

brunhilda.cpp:58:11: error: redefinition of 'const int N'
   58 | const int N = 1e5 + 2;
      |           ^
brunhilda.cpp:9:11: note: 'const int N' previously defined here
    9 | const int N = 1e5 + 2;
      |           ^
brunhilda.cpp:59:11: error: redefinition of 'const int M'
   59 | const int M = 1e5 + 2;
      |           ^
brunhilda.cpp:10:11: note: 'const int M' previously defined here
   10 | const int M = 1e5 + 2;
      |           ^
brunhilda.cpp:60:11: error: redefinition of 'const int inf'
   60 | const int inf = 2e9;
      |           ^~~
brunhilda.cpp:11:11: note: 'const int inf' previously defined here
   11 | const int inf = 2e9;
      |           ^~~
brunhilda.cpp:61:13: error: redefinition of 'std::vector<int> primes [100002]'
   61 | vector<int> primes[M];
      |             ^~~~~~
brunhilda.cpp:12:13: note: 'std::vector<int> primes [100002]' previously declared here
   12 | vector<int> primes[M];
      |             ^~~~~~
brunhilda.cpp:62:5: error: redefinition of 'int idx [100002]'
   62 | int idx[M], ans[N], koji[M], dp[M];
      |     ^~~
brunhilda.cpp:13:5: note: 'int idx [100002]' previously declared here
   13 | int idx[M], ans[N], koji[M], dp[M];
      |     ^~~
brunhilda.cpp:62:13: error: redefinition of 'int ans [100002]'
   62 | int idx[M], ans[N], koji[M], dp[M];
      |             ^~~
brunhilda.cpp:13:13: note: 'int ans [100002]' previously declared here
   13 | int idx[M], ans[N], koji[M], dp[M];
      |             ^~~
brunhilda.cpp:62:21: error: redefinition of 'int koji [100002]'
   62 | int idx[M], ans[N], koji[M], dp[M];
      |                     ^~~~
brunhilda.cpp:13:21: note: 'int koji [100002]' previously declared here
   13 | int idx[M], ans[N], koji[M], dp[M];
      |                     ^~~~
brunhilda.cpp:62:30: error: redefinition of 'int dp [100002]'
   62 | int idx[M], ans[N], koji[M], dp[M];
      |                              ^~
brunhilda.cpp:13:30: note: 'int dp [100002]' previously declared here
   13 | int idx[M], ans[N], koji[M], dp[M];
      |                              ^~
brunhilda.cpp:63:5: error: redefinition of 'int main()'
   63 | int main() {
      |     ^~~~
brunhilda.cpp:14:5: note: 'int main()' previously defined here
   14 | int main() {
      |     ^~~~