結果
問題 | No.590 Replacement |
ユーザー | Lepton_s |
提出日時 | 2017-11-04 00:53:58 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,462 bytes |
コンパイル時間 | 894 ms |
コンパイル使用メモリ | 95,608 KB |
実行使用メモリ | 18,688 KB |
最終ジャッジ日時 | 2024-11-23 15:39:57 |
合計ジャッジ時間 | 89,274 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 3 ms
11,136 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | AC | 3 ms
13,184 KB |
testcase_34 | WA | - |
testcase_35 | AC | 4 ms
13,312 KB |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | RE | - |
testcase_45 | TLE | - |
testcase_46 | TLE | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:61:17: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘ll*’ {aka ‘long long int*’} [-Wformat=] 61 | scanf("%d", &n); | ~^ ~~ | | | | | ll* {aka long long int*} | int* | %lld main.cpp:61:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 61 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:63:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 63 | scanf("%lld", a[i]+j); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
// kinen submit #include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <sstream> #include <functional> #include <map> #include <string> #include <cstring> #include <vector> #include <queue> #include <stack> #include <deque> #include <set> #include <list> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> P; typedef pair<P,ll> PP; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const ll INF = 1LL<<29; const ll mod = 1e9+7; #define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i)) #define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d)) #define all(v) (v).begin(), (v).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset((m),(v),sizeof(m)) #define chmin(X,Y) ((X)>(Y)?X=(Y),true:false) #define chmax(X,Y) ((X)<(Y)?X=(Y),true:false) #define fst first #define snd second #define UNIQUE(x) (x).erase(unique(all(x)),(x).end()) template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;} #define N 100100 ll n; ll a[2][N], c[2][N], p[2][N], pr[2][N], used[N], ix[N], lp[N], dd[N], rr[N]; map<PP, vector<ll>> s; void extgcd(ll x, ll y, ll &a, ll &b, ll &g){ if(y == 0){ a = 1; b = 0; g = x; } else { extgcd(y, x%y, a, b, g); swap(a, b); b -= a*x/y; } } int main(){ scanf("%d", &n); rep(i, 2) rep(j, n){ scanf("%lld", a[i]+j); a[i][j]--; } mset(p, -1); rep(i, 2) rep(j, n){ if(p[i][j] != -1) continue; ll k = a[i][j]; p[i][j] = 1; while(k != j){ c[i][k] = p[i][j]++; pr[i][k] = j; k = a[i][k]; } pr[i][j] = j; } ll res = 0; rep(j, n){ ll b[2], d; extgcd(p[0][j], p[1][j], b[0], b[1], d); ll r[2], q[2]; rep(i, 2) r[i] = c[i][j]%d; if(r[1]<r[0]) r[1] += d; rep(i, 2) q[i] = c[i][j]/d; ll qq = q[1]-q[0]; b[0] *= qq; b[0] %= p[1][j]/d; if(b[0]<0) b[0] += p[1][j]/d; b[1] * -qq; b[1] %= p[0][j]/d; if(b[1]<0) b[1] += p[0][j]/d; ix[j] = b[0]*p[0][j]*d+r[0]; lp[j] = p[0][j]/d*p[1][j]/d; dd[j] = d; rr[j] = r[1]-r[0]; s[PP(P(pr[0][j], pr[1][j]), r[j])].push_back(j); } for(auto &&x: s){ auto &&v = x.snd; int m = v.size(); vector<ll> vv(m+1); rep(i, m) vv[i] = ix[v[i]]; v[m] = vv[0]+lp[v[0]]; rep(i, m){ ll y = vv[i+1]-vv[i]-1; res += y*(y+1)/2; res %= mod; } } cout<<res<<endl; return 0; }