結果

問題 No.551 夏休みの思い出(2)
ユーザー 小指が強い人小指が強い人
提出日時 2017-08-20 02:41:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,915 bytes
コンパイル時間 2,435 ms
コンパイル使用メモリ 180,916 KB
実行使用メモリ 336,540 KB
最終ジャッジ日時 2024-04-22 17:25:18
合計ジャッジ時間 11,894 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 13 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 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 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 574 ms
42,340 KB
testcase_28 AC 545 ms
42,340 KB
testcase_29 AC 100 ms
6,408 KB
testcase_30 AC 427 ms
27,876 KB
testcase_31 AC 105 ms
6,280 KB
testcase_32 AC 390 ms
27,112 KB
testcase_33 AC 579 ms
42,472 KB
testcase_34 AC 337 ms
23,008 KB
testcase_35 AC 107 ms
8,072 KB
testcase_36 AC 234 ms
14,752 KB
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #


#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < (ll)n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T, class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<char c = ' ',class T> void write(T a){cout << fixed << setprecision(12) << a << endl;}
template<char c = ' ',class T,class ...Args> void write(T a, Args... args){cout << fixed << setprecision(4) << a << c; write<c>(args...);}
template<class T> void warr(T a, const char* c = " "){cout << a;for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ull gcd(ull a, ull b){while(true){ull k = a % b;if(k == 0)return b;a = b;b = k;}}
ull comb(ull n, ull m){ull p=1;m=min(m,n-m);for(ull i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

ull power( const ull& a, ull k, const ull& n )
{
  if ( a == 0 || n == 0 ) return( 0 );
  if ( k == 0 ) return( 1 % n );

  ull currentMod = a % n;
  ull currentValue = ( ( k & 1 ) > 0 ) ? currentMod : 1;

  for ( k >>= 1 ; k > 0 ; k >>= 1 ) {
    currentMod = ( currentMod * currentMod ) % n;
    if ( ( k & 1 ) > 0 )
      currentValue = ( currentValue * currentMod ) % n;
  }

  return( currentValue );
}

int main(void)
{
    ll p,r,q;
    unordered_map<int,int> mp;
    read(p,r,q);
    ll w,h;
    if(p<1e6){
        w=h=ceil(sqrt(p));
    }
    else {
        w=ceil(p/100.0);
        h=100;
    }
    ll ri=1;
    rep(i,w){
        mp[ri]=i;
        ri=(ri*r)%p;
    }
    //int i2=power(2,p-2,p);
    int d2p=(p-1)/2;
    ll irm=power(power(r,p-2,p),w,p);
    rep(i,q){
        ll a,b,c;
        read(a,b,c);
        if(b==0&&c==0){
            write(0);
            continue;
        }
        ll i2a=power(2*a,p-2,p);
        ll d=(((b*b)%p)-4*((a*c)%p))%p;
        if(d==0){
            write(((-b+p)*i2a)%p);
            continue;
        }
        if(d<0)d=(d+p)%p;
        ll v=d;
        set<int> res;
        rep(j,h){
            auto it=mp.find(v);
            if(it!=mp.end()){
                ll x=j*w+it->second;
                //write(i,x);
                if(x%2==0){
                    ll gx1=power(r,x/2,p);
                    ll gx2=power(r,x/2+d2p,p);
                    ll x1=(gx1-b+p)*i2a;
                    ll x2=(gx2-b+p)*i2a;
                    res.insert(x1%p);
                    res.insert(x2%p);
                    break;
                }
            }
            v=(v*irm)%p;
        }
        //continue;
        if(res.size()>0){
            bool init=false;
            for(auto a:res){
                if(init)cout<<" ";
                cout<<a;
                init=true;
            }
            cout<<endl;
        }
        else write(-1);
    }
    return 0;
}
0