結果
問題 | No.551 夏休みの思い出(2) |
ユーザー | fumofumofuni |
提出日時 | 2022-08-27 11:33:10 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,320 ms / 4,000 ms |
コード長 | 2,046 bytes |
コンパイル時間 | 2,177 ms |
コンパイル使用メモリ | 207,984 KB |
実行使用メモリ | 46,068 KB |
最終ジャッジ日時 | 2024-04-22 10:46:22 |
合計ジャッジ時間 | 19,666 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 23 ms
5,248 KB |
testcase_01 | AC | 22 ms
5,376 KB |
testcase_02 | AC | 23 ms
5,376 KB |
testcase_03 | AC | 24 ms
5,376 KB |
testcase_04 | AC | 29 ms
5,376 KB |
testcase_05 | AC | 35 ms
5,376 KB |
testcase_06 | AC | 39 ms
5,376 KB |
testcase_07 | AC | 24 ms
5,376 KB |
testcase_08 | AC | 23 ms
5,376 KB |
testcase_09 | AC | 23 ms
5,376 KB |
testcase_10 | AC | 22 ms
5,376 KB |
testcase_11 | AC | 23 ms
5,376 KB |
testcase_12 | AC | 22 ms
5,376 KB |
testcase_13 | AC | 22 ms
5,376 KB |
testcase_14 | AC | 23 ms
5,376 KB |
testcase_15 | AC | 23 ms
5,376 KB |
testcase_16 | AC | 23 ms
5,376 KB |
testcase_17 | AC | 76 ms
13,976 KB |
testcase_18 | AC | 186 ms
30,824 KB |
testcase_19 | AC | 169 ms
29,284 KB |
testcase_20 | AC | 182 ms
30,692 KB |
testcase_21 | AC | 286 ms
44,536 KB |
testcase_22 | AC | 39 ms
6,412 KB |
testcase_23 | AC | 53 ms
9,848 KB |
testcase_24 | AC | 136 ms
23,760 KB |
testcase_25 | AC | 72 ms
13,592 KB |
testcase_26 | AC | 126 ms
23,140 KB |
testcase_27 | AC | 553 ms
45,816 KB |
testcase_28 | AC | 571 ms
45,812 KB |
testcase_29 | AC | 462 ms
45,944 KB |
testcase_30 | AC | 550 ms
45,812 KB |
testcase_31 | AC | 468 ms
45,940 KB |
testcase_32 | AC | 584 ms
45,940 KB |
testcase_33 | AC | 541 ms
45,936 KB |
testcase_34 | AC | 518 ms
45,936 KB |
testcase_35 | AC | 470 ms
45,816 KB |
testcase_36 | AC | 521 ms
45,808 KB |
testcase_37 | AC | 1,320 ms
45,816 KB |
testcase_38 | AC | 1,110 ms
45,944 KB |
testcase_39 | AC | 622 ms
45,940 KB |
testcase_40 | AC | 915 ms
45,772 KB |
testcase_41 | AC | 590 ms
46,068 KB |
testcase_42 | AC | 1,130 ms
45,812 KB |
testcase_43 | AC | 622 ms
45,812 KB |
testcase_44 | AC | 712 ms
45,808 KB |
testcase_45 | AC | 660 ms
45,944 KB |
testcase_46 | AC | 1,261 ms
45,812 KB |
testcase_47 | AC | 22 ms
5,376 KB |
testcase_48 | AC | 24 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function 'll modlog(ll)': main.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type] 65 | } | ^
ソースコード
#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; } unordered_map<ll,ll> mp; ll modlog(ll s){ ll f=1; if(mp.size()==0){ rep(i,1000000){ mp[f]=i; f=f*r%p; } } ll dif=modpow(r,1000000,p); dif=modpow(dif,p-2,p); f=s; rep(i,1000){ if(mp.count(f)){ return (mp[f]+i*1000000)%(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(); }