結果

問題 No.551 夏休みの思い出(2)
ユーザー char134217728char134217728
提出日時 2017-08-15 09:35:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,628 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 170,088 KB
実行使用メモリ 66,288 KB
最終ジャッジ日時 2024-04-21 12:28:44
合計ジャッジ時間 28,618 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 AC 14 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 170 ms
19,072 KB
testcase_18 AC 677 ms
47,360 KB
testcase_19 AC 599 ms
44,416 KB
testcase_20 AC 648 ms
47,232 KB
testcase_21 AC 967 ms
63,488 KB
testcase_22 AC 34 ms
8,448 KB
testcase_23 AC 89 ms
13,824 KB
testcase_24 AC 384 ms
33,024 KB
testcase_25 AC 153 ms
18,432 KB
testcase_26 AC 370 ms
31,872 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:28:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
   28 | main(){
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int inf = 1e9;
const int mod = 1e9+7;

ll p, q, r;
map<ll, ll> m;
ll qu[3][10000];
vector<pair<ll, int> > li;
ll powMod(ll a, ll n, ll m){
  ll p = 1;
  while(n > 0){
    if(n & 1) p = p * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return p;
}

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> p >> r >> q;
  ll inv2 = powMod(2, p - 2, p), invr = powMod(r, p - 2, p);
  FOR(i, 0, q){
    ll a, b, c, d;
    cin >> a >> b >> c;
    d = powMod(a, p - 2, p);
    b = b * d % p * inv2 % p;
    c = c * d % p;
    d = b * b % p;
    c = (d - c + p) % p;
    qu[0][i] = b;
    qu[1][i] = c;
    qu[2][i] = -1;
    if(c != 0){
      li.pb(pair<ll, int>(c, i));
    }
  }
  ll a = 1, e = min(p-1, 1000000ll);
  FOR(i, 0, e){
    m[a] = ll(i);
    a = a * r % p;
  }
  FOR(i, 0, 1+p/e){
    FOR(j, 0, li.size()){
      if(m.find(li[j].first) != m.end()){
        qu[2][li[j].second] = i*e + m[li[j].first];
      }
      li[j].first = li[j].first * a % p;
    }
  }
  FOR(i, 0, q){
    if(qu[1][i] == 0){
      cout << (p - qu[0][i])%p << endl;
    }else if(qu[2][i] % 2 != 0){
      cout << -1 << endl;
    }else{
      ll ans1, ans2;
      ans1 = (powMod(r, qu[2][i] / 2, p) - qu[0][i] + p)%p;
      ans2 = (powMod(r, qu[2][i] / 2 + (p-1) / 2, p) - qu[0][i] + p)%p;
      if(ans1 > ans2)swap(ans1, ans2);
      cout << ans1 << " " << ans2 << endl;
    }
  }
}
0