답안 #784475

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

#define int long long

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

signed main() {
  __uint128_t temp;
  // int temp;
  int size;
  cin >> n >> a >> b;
  temp = a*b;
  if ((b+1 % a) == 0) size = b;
  else if (temp > maks) size = maks;
  else 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;
  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});
  }

  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:41: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]
   41 |   for (int i = 0; i < sg.size(); i++) {
      |                   ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1067 ms 1032 KB Output is correct
3 Correct 2387 ms 1024 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 16 ms 356 KB Output is correct
3 Correct 14 ms 356 KB Output is correct
4 Correct 21 ms 340 KB Output is correct
5 Execution timed out 5045 ms 1544 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 5071 ms 1340 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 5071 ms 1340 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 5071 ms 1340 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 5031 ms 1384 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1067 ms 1032 KB Output is correct
3 Correct 2387 ms 1024 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -