結果

問題 No.97 最大の値を求めるくえり
ユーザー not_522not_522
提出日時 2015-08-19 17:47:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 740 ms / 5,000 ms
コード長 3,792 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 154,988 KB
実行使用メモリ 21,848 KB
最終ジャッジ日時 2023-09-25 13:21:14
合計ジャッジ時間 9,064 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
18,528 KB
testcase_01 AC 73 ms
21,636 KB
testcase_02 AC 318 ms
18,832 KB
testcase_03 AC 318 ms
18,828 KB
testcase_04 AC 221 ms
18,836 KB
testcase_05 AC 224 ms
18,564 KB
testcase_06 AC 224 ms
18,520 KB
testcase_07 AC 229 ms
19,040 KB
testcase_08 AC 242 ms
18,672 KB
testcase_09 AC 261 ms
18,464 KB
testcase_10 AC 302 ms
18,784 KB
testcase_11 AC 338 ms
18,672 KB
testcase_12 AC 377 ms
18,840 KB
testcase_13 AC 740 ms
18,780 KB
testcase_14 AC 486 ms
18,832 KB
testcase_15 AC 351 ms
18,740 KB
testcase_16 AC 299 ms
19,340 KB
testcase_17 AC 277 ms
20,320 KB
testcase_18 AC 289 ms
21,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace arithmetic {
  template<typename T> class Addition {
  public:
    template<typename V> T operator+(const V& v) const {
      return T(static_cast<const T&>(*this)) += v;
    }
  };

  template<typename T> class Subtraction {
  public:
    template<typename V> T operator-(const V& v) const {
      return T(static_cast<const T&>(*this)) -= v;
    }
  };

  template<typename T> class Multiplication {
  public:
    template<typename V> T operator*(const V& v) const {
      return T(static_cast<const T&>(*this)) *= v;
    }
  };

  template<typename T> class Division {
  public:
    template<typename V> T operator/(const V& v) const {
      return T(static_cast<const T&>(*this)) /= v;
    }
  };

  template<typename T> class Modulus {
  public:
    template<typename V> T operator%(const V& v) const {
      return T(static_cast<const T&>(*this)) %= v;
    }
  };
}

template<typename T> class IndivisibleArithmetic : public arithmetic::Addition<T>, public arithmetic::Subtraction<T>, public arithmetic::Multiplication<T> {};

template<typename T> class Arithmetic : public IndivisibleArithmetic<T>, public arithmetic::Division<T> {};

class Inverse {
private:
  long long mod;
	vector<long long> inv;
  
public:
  Inverse() {}
  
	Inverse(long long mod, long long n = 1000000) : mod(mod) {
    inv = vector<long long>(n, 1);
    for (int i = 2; i < n; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
  }
  
	long long operator()(long long a) const {
		if (a < (int)inv.size()) return inv[a];
		long long b = mod, x = 1, y = 0;
		while (b) {
			long long t = a / b;
			swap(a -= t * b, b);
			swap(x -= t * y, y);
		}
		return (x %= mod) < 0 ? x + mod : x;
	}
};

class Mint : public Arithmetic<Mint> {
private:
  static long long mod;
  static Inverse inverse;
  long long val;

public:
	Mint() {}

	Mint(const long long& val) {
    this->val = val % mod;
    if (this->val < 0) this->val += mod;
  }

  static void setMod(const long long& m) {
    mod = m;
    inverse = Inverse(m);
  }

	Mint operator+=(const Mint& m) {
		val += m.val;
		if (val >= mod) val -= mod;
		return *this;
	}

	Mint operator-=(const Mint& m) {
		val -= m.val;
		if (val < 0) val += mod;
		return *this;
	}

	Mint operator*=(const Mint& m) {
		val *= m.val;
		val %= mod;
		return *this;
	}

	Mint operator/=(const Mint& m) {
		val *= inverse(m.val);
		val %= mod;
		return *this;
	}

	Mint operator++() {return val += 1;}

	Mint operator--() {return val -= 1;}

	operator long long() {
		return val;
	}

  Mint identity() const {
    return 1;
  }
};

long long Mint::mod = 1000000007;
Inverse Mint::inverse(1000000007);

ostream& operator<<(ostream& os, Mint a) {
	os << (long long)a;
	return os;
}

istream& operator>>(istream& is, Mint& a) {
	long long n;
	is >> n;
	a = n;
	return is;
}

unsigned xor128_x = 123456789, xor128_y = 362436069, xor128_z = 521288629, xor128_w = 88675123;
unsigned xor128() {
	unsigned t = xor128_x ^ (xor128_x << 11);
	xor128_x = xor128_y; xor128_y = xor128_z; xor128_z = xor128_w;
	return xor128_w = xor128_w ^ (xor128_w >> 19) ^ (t ^ (t >> 8));
}
void generateA(int N, int A[]) {
  for(int i = 0; i < N; ++ i)
  A[i] = xor128() % 100003;
}

int main() {
  int n, q;
  cin >> n >> q;
  int a[n];
  generateA(n, a);
  unordered_set<int> s;
  for (int i : a) s.insert(i);
  const int MOD = 100003;
  Mint::setMod(MOD);
  for (int i = 0; i < q; ++i) {
    long long k;
    cin >> k;
    if (k == 0) {
      cout << 0 << endl;
    } else if (n < 1000) {
      long long res = 0;
      for (int j : a) res = max(res, j * k % MOD);
      cout << res << endl;
    } else {
      for (Mint i = MOD - 1; ; --i) {
        if (s.count(i / k)) {
          cout << i << endl;
          break;
        }
      }
    }
  }
}
0