結果

問題 No.551 夏休みの思い出(2)
ユーザー fumofumofunifumofumofuni
提出日時 2022-08-27 11:27:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,008 bytes
コンパイル時間 2,406 ms
コンパイル使用メモリ 207,828 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 10:41:18
合計ジャッジ時間 19,175 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
5,248 KB
testcase_01 AC 56 ms
5,376 KB
testcase_02 AC 170 ms
5,376 KB
testcase_03 AC 737 ms
5,376 KB
testcase_04 AC 1,251 ms
5,376 KB
testcase_05 AC 2,926 ms
5,376 KB
testcase_06 TLE -
testcase_07 AC 64 ms
5,376 KB
testcase_08 AC 64 ms
5,376 KB
testcase_09 AC 64 ms
5,376 KB
testcase_10 AC 61 ms
5,376 KB
testcase_11 AC 66 ms
5,376 KB
testcase_12 AC 63 ms
5,376 KB
testcase_13 AC 65 ms
5,376 KB
testcase_14 AC 60 ms
5,376 KB
testcase_15 AC 63 ms
5,376 KB
testcase_16 AC 62 ms
5,376 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 AC 3 ms
5,376 KB
testcase_48 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'll modlog(ll)':
main.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
   63 | }
      | ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,1,0,-1,1,-1,1,-1,0};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

ll modpow(ll a,ll n, ll mod) {
  a%=mod;if(a==0)return 0;
  ll res = 1;
  while (n > 0) {
      if (n & 1) res = res * a % mod;
      a = a * a % mod;
      n >>= 1;
  }
  return res;
}
ll p,r;
ll safemod(ll x){
  return (x%p+p)%p;
}
ll modlog(ll s){
  unordered_map<ll,ll> mp;
  ll f=1;
  rep(i,32000){
    mp[f]=i;
    f=f*r%p;
  }
  ll dif=modpow(r,32000,p);
  dif=modpow(dif,p-2,p);
  f=s;
  rep(i,32000){
    if(mp.count(f)){
      return (mp[f]+i*32000)%(p-1);
    }
    f*=dif;
  }
}
void solve(){
  ll a,b,c;cin >> a >> b >> c;
  ll s=safemod(b*b-4*a*c);
  if(s==0){
    cout << safemod(-b*modpow(a*2,p-2,p)) << endl;return;
  }
  ll k=modlog(s);
  if(k&1){
    cout << -1 << endl;
    return ;
  }
  //cout << k << endl;
  ll x=k/2,y=(k+p-1)/2;
  x=modpow(r,x,p),y=modpow(r,y,p);
  vl ans={x,-x,y,-y};
  ll inva=modpow(a*2,p-2,p);
  rep(i,4){
    ans[i]=safemod((ans[i]-b)*inva);
  }
  sort(all(ans));ans.erase(unique(all(ans)),ans.end());
  for(auto p:ans)cout << p << " ";cout << endl;
}
int main(){
  cin >> p >> r;
  ll t;cin >> t;
  while(t--)solve();
}
0