結果

問題 No.551 夏休みの思い出(2)
ユーザー fumofumofunifumofumofuni
提出日時 2022-08-27 11:29:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,011 bytes
コンパイル時間 3,325 ms
コンパイル使用メモリ 208,096 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-22 10:42:47
合計ジャッジ時間 23,868 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,812 KB
testcase_01 AC 60 ms
5,376 KB
testcase_02 AC 184 ms
5,376 KB
testcase_03 AC 799 ms
5,376 KB
testcase_04 AC 1,364 ms
5,376 KB
testcase_05 AC 3,163 ms
5,376 KB
testcase_06 TLE -
testcase_07 AC 69 ms
5,376 KB
testcase_08 AC 68 ms
5,376 KB
testcase_09 AC 70 ms
5,376 KB
testcase_10 AC 67 ms
5,376 KB
testcase_11 AC 71 ms
5,376 KB
testcase_12 AC 68 ms
5,376 KB
testcase_13 AC 71 ms
5,376 KB
testcase_14 AC 68 ms
5,376 KB
testcase_15 AC 69 ms
5,376 KB
testcase_16 AC 70 ms
5,376 KB
testcase_17 AC 464 ms
5,376 KB
testcase_18 AC 447 ms
5,376 KB
testcase_19 AC 456 ms
5,376 KB
testcase_20 AC 475 ms
5,376 KB
testcase_21 AC 468 ms
5,376 KB
testcase_22 AC 430 ms
5,376 KB
testcase_23 AC 437 ms
5,376 KB
testcase_24 AC 457 ms
5,376 KB
testcase_25 AC 448 ms
5,376 KB
testcase_26 AC 467 ms
5,376 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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=f*dif%p;
  }
}
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