제출 #679631

#제출 시각아이디문제언어결과실행 시간메모리
679631as111Sirni (COCI17_sirni)C++14
0 / 140
2136 ms300764 KiB
#include <bits/stdc++.h> #define MAXN 100000 using namespace std; typedef pair<int, int> pi; const int MAXP = 1e7; int N; set<int> cards; vector<pi> edges[MAXP + 5]; // PQ of edges priority_queue<pair<int, pi>> PQ; int parent[MAXN + 5]; // initialize parent[i] = i int findRoot(int a) { return parent[a] = (parent[a] == a ? a : findRoot(parent[a])); } int join(int a, int b) { a = findRoot(a); b = findRoot(b); if (a == b) return 0; parent[a] = b; return 1; } int card[MAXN + 5]; // value for each card ID map<int, int> ID; // card value to card ID int main() { cin >> N; for (int i = 0; i < N; i++) { int P; cin >> P; cards.insert(P); } int i = 1; for (int c : cards) { ID[c] = i; card[i] = c; parent[i] = i; i++; } for (int i = 1; i <= cards.size();i++) { int s = i + 1; for (int j = card[i]; j < MAXP; j += card[i]) { while (s < cards.size() && card[s] < j) s++; if (s < cards.size()) edges[card[s] % card[i]].emplace_back(i, s); } } long long ans = 0; for (int p = 0; p < MAXP;p++) { for (auto curr : edges[p]) { int f = curr.first; int s = curr.second; if (join(f, s))ans += p; } } cout << ans<<endl; }

컴파일 시 표준 에러 (stderr) 메시지

sirni.cpp: In function 'int main()':
sirni.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for (int i = 1; i <= cards.size();i++) {
      |                  ~~^~~~~~~~~~~~~~~
sirni.cpp:43:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |    while (s < cards.size() && card[s] < j) s++;
      |           ~~^~~~~~~~~~~~~~
sirni.cpp:44:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    if (s < cards.size()) edges[card[s] % card[i]].emplace_back(i, s);
      |        ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...