제출 #989539

#제출 시각아이디문제언어결과실행 시간메모리
989539aykhnPalembang Bridges (APIO15_bridge)C++17
22 / 100
39 ms8680 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 0x3F3F3F3F3F3F3F3F signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int k, n, S = 0; cin >> k >> n; vector<int> id, p, s; for (int i = 0; i < n; i++) { char a, b; int l, r; cin >> a >> l >> b >> r; if (l > r) swap(l, r); if (a == b) S += r - l; else id.push_back(l), id.push_back(r); } if (id.empty()) { cout << S << '\n'; return 0; } sort(id.begin(), id.end()); p = s = id; for (int i = 1; i < p.size(); i++) p[i] += p[i - 1]; for (int i = (int)s.size() - 2; i >= 0; i--) s[i] += s[i + 1]; s.push_back(0); int res = inf; for (int i = 0; i < id.size(); i++) { res = min(res, s[i + 1] - p[i] + id[i] * (2 * (i + 1) - (int)id.size())); } cout << res + S + (int)id.size() / 2 << '\n'; }

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

bridge.cpp: In function 'int main()':
bridge.cpp:31:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for (int i = 1; i < p.size(); i++) p[i] += p[i - 1];
      |                   ~~^~~~~~~~~~
bridge.cpp:35:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int i = 0; i < id.size(); i++)
      |                   ~~^~~~~~~~~~~
#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...