답안 #784496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784496 2023-07-16T07:30:15 Z andecaandeci 이상한 기계 (APIO19_strange_device) C++17
5 / 100
1354 ms 33400 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
// #define i128 long long
#define i128 __int128_t

int n, a, b;
vector<pair<int, int>> sg;
const int maks = 1e18;

// i128 gcd(i128 a, i128 b) {
//   if (b == 0) return a;
//   return gcd(b, a%b);
// }

bool comp(pair<int, int> a, pair<int, int> b) {
  return a.first < b.first or (a.first == b.first and a.second < b.second);
}

signed main() {
  i128 temp;
  // int temp;
  int size;
  cin >> n >> a >> b;
  temp = (a/__gcd(a,b+1))*b;
  // if ((b+1 % a) == 0) size = b;
  // if (temp > maks) size = maks;
  // else size = temp;
  size = temp;

  int l, r;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    // cout << l << " " << r << endl;
    if (r - l + 1 >= size) {
      cout << size << endl;
      return 0;
    } else if (l%size > r%size) {
      sg.push_back({l%size, 1});
      sg.push_back({size-1, 2});
      sg.push_back({0, 1});
      sg.push_back({r%size, 2});
    } else {
      sg.push_back({l%size, 1});
      sg.push_back({r%size, 2});
    }
  }
  sort(sg.begin(), sg.end());

  int cnt = 0, l2, ans = 0;
  // vector<pair<int, int>> ans;
  for (int i = 0; i < sg.size(); i++) {
    // cout << sg[i].first << " " << sg[i].second << endl;
    if (sg[i].second == 1) {
      if (cnt == 0) l2 = sg[i].first;
      cnt++;
    } else cnt--;

    if (cnt == 0) {
      // ans.push_back({l2, sg[i].first});
      ans += sg[i].first-l2+1.;
    }
  }
  cout << ans << endl;

  // int res = 0;
  // for (auto i: ans) {
  //   // cout << i.first << " " << i.second << endl;
  //   res += (i.second - i.first + 1);
  // }
  // cout << res << endl;

}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:53:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for (int i = 0; i < sg.size(); i++) {
      |                   ~~^~~~~~~~~~~
strange_device.cpp:62:25: warning: 'l2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |       ans += sg[i].first-l2+1.;
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 18 ms 848 KB Output is correct
3 Correct 12 ms 848 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 12 ms 848 KB Output is correct
17 Correct 128 ms 4612 KB Output is correct
18 Incorrect 0 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 819 ms 33192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1185 ms 33312 KB Output is correct
3 Correct 1172 ms 33244 KB Output is correct
4 Incorrect 1161 ms 33148 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1185 ms 33312 KB Output is correct
3 Correct 1172 ms 33244 KB Output is correct
4 Incorrect 1161 ms 33148 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1185 ms 33312 KB Output is correct
3 Correct 1172 ms 33244 KB Output is correct
4 Incorrect 1161 ms 33148 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 117 ms 4476 KB Output is correct
3 Correct 123 ms 4496 KB Output is correct
4 Correct 1354 ms 33400 KB Output is correct
5 Correct 120 ms 4412 KB Output is correct
6 Correct 118 ms 4508 KB Output is correct
7 Correct 119 ms 4500 KB Output is correct
8 Correct 119 ms 4576 KB Output is correct
9 Correct 116 ms 4516 KB Output is correct
10 Correct 131 ms 4448 KB Output is correct
11 Correct 117 ms 4484 KB Output is correct
12 Incorrect 119 ms 4504 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 18 ms 848 KB Output is correct
3 Correct 12 ms 848 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 12 ms 848 KB Output is correct
17 Correct 128 ms 4612 KB Output is correct
18 Incorrect 0 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -