/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 2ms 504.0 KiB
#4 Accepted 2ms 532.0 KiB
#5 Accepted 2ms 324.0 KiB
#6 Accepted 2ms 324.0 KiB

Code


#include <vector>
#include <cassert>
#include <iostream>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.length();
  assert(n > 2);
  assert(s[0] == 'y' && s[1] == '=');
  int ptr = 2;
  int M = 0, neg = 0;
  if (s[ptr] == 'x') {
    M = 1;
  } else {
    if (s[ptr] == '+') ptr += 1;
    if (s[ptr] == '-') neg = 1, ptr += 1;
    while (ptr < n && s[ptr] != 'x') {
      assert('0' <= s[ptr] && s[ptr] <= '9');
      M = M * 10 + s[ptr] - '0';
      ptr += 1;
    }
    if (neg) M *= -1;
  }
  assert(s[ptr] == 'x');
  ptr += 1;
  int C = 0; neg = 0;
  if (ptr < n && s[ptr] == '+') ptr += 1;
  if (ptr < n && s[ptr] == '-') neg = 1, ptr += 1;
  while (ptr < n) {
    assert('0' <= s[ptr] && s[ptr] <= '9');
    C = C * 10 + s[ptr] - '0';
    ptr += 1;
  }
  if (neg) C  *= -1;
  int q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    cout << (y == x * M + C ? "YES" : "NO") << '\n';
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1015 Friend in need is a friend indeed
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-07 10:27:48
Judged At
2024-11-11 03:30:59
Judged By
Score
100
Total Time
2ms
Peak Memory
532.0 KiB