結果
問題 | No.1864 Shortest Paths Counting |
ユーザー | t_mk |
提出日時 | 2022-03-15 20:26:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 877 ms / 2,000 ms |
コード長 | 1,875 bytes |
コンパイル時間 | 2,341 ms |
コンパイル使用メモリ | 194,596 KB |
実行使用メモリ | 54,272 KB |
最終ジャッジ日時 | 2024-09-22 12:41:44 |
合計ジャッジ時間 | 18,363 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
19,796 KB |
testcase_01 | AC | 6 ms
19,756 KB |
testcase_02 | AC | 6 ms
19,760 KB |
testcase_03 | AC | 7 ms
19,764 KB |
testcase_04 | AC | 7 ms
19,764 KB |
testcase_05 | AC | 7 ms
19,748 KB |
testcase_06 | AC | 7 ms
19,756 KB |
testcase_07 | AC | 6 ms
19,688 KB |
testcase_08 | AC | 7 ms
19,760 KB |
testcase_09 | AC | 757 ms
54,128 KB |
testcase_10 | AC | 780 ms
54,144 KB |
testcase_11 | AC | 787 ms
54,088 KB |
testcase_12 | AC | 852 ms
54,160 KB |
testcase_13 | AC | 798 ms
54,132 KB |
testcase_14 | AC | 807 ms
54,124 KB |
testcase_15 | AC | 783 ms
54,060 KB |
testcase_16 | AC | 752 ms
54,056 KB |
testcase_17 | AC | 767 ms
54,064 KB |
testcase_18 | AC | 798 ms
54,272 KB |
testcase_19 | AC | 811 ms
54,128 KB |
testcase_20 | AC | 877 ms
54,184 KB |
testcase_21 | AC | 833 ms
54,072 KB |
testcase_22 | AC | 766 ms
53,972 KB |
testcase_23 | AC | 754 ms
54,064 KB |
testcase_24 | AC | 6 ms
19,708 KB |
testcase_25 | AC | 563 ms
41,764 KB |
testcase_26 | AC | 710 ms
54,056 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:72:23: warning: 'last' may be used uninitialized [-Wmaybe-uninitialized] 72 | for(int i = start;i <= last;i++){ | ~~^~~~~~~ main.cpp:64:13: note: 'last' was declared here 64 | int start,last; | ^~~~ main.cpp:75:5: warning: 'start' may be used uninitialized [-Wmaybe-uninitialized] 75 | if(i == start)dp[i] = 1; | ^~ main.cpp:64:7: note: 'start' was declared here 64 | int start,last; | ^~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0;i < (n);i++) using ll = long long; int mod = 998244353; using P = pair<double,double>; int LEN = 1 << 20; vector<ll> seg(2*LEN,0); void add(int ind,ll val){ ind += LEN; seg[ind] += val; while(ind > 0){ ind /= 2; seg[ind] = seg[ind*2] + seg[ind*2+1]; seg[ind] %= mod; } } ll sum(int l,int r){ l += LEN; r += LEN; ll ans = 0; while(l < r){ if(l % 2 == 1)ans += seg[l++]; l /= 2; if(r % 2 == 1)ans += seg[--r]; r /= 2; ans %= mod; } return ans; } int main(){ int n; cin >> n; vector<P> pos(n); rep(i,n){ double x,y; cin >> x >> y; pos[i].first = (x + y)/2 + 1e9; pos[i].second = (x - y)/2 + 1e9; } if(pos[0].second > pos[n-1].second){ rep(i,n){ pos[i].second *= (-1);pos[i].second += 2e9; } } if(pos[0].first > pos[n-1].first){ rep(i,n){ pos[i].first *= (-1);pos[i].first += 2e9; } } vector<double> x(n),y(n); rep(i,n){ x[i] = pos[i].first; y[i] = pos[i].second; } sort(x.begin(),x.end()); sort(y.begin(),y.end()); map<double,int> mpX,mpY; rep(i,n)mpX[x[i]] = lower_bound(x.begin(),x.end(),x[i]) - x.begin(); rep(i,n)mpY[y[i]] = lower_bound(y.begin(),y.end(),y[i]) - y.begin(); vector<tuple<int,int,int>> pos2(n); rep(i,n)pos2[i] = make_tuple(mpX[pos[i].first],mpY[pos[i].second],i); sort(pos2.begin(),pos2.end()); int start,last; rep(i,n){ int a,b,c; tie(a,b,c) = pos2[i]; if(a == mpX[pos[0].first] && b == mpY[pos[0].second])start = i; if(a == mpX[pos[n-1].first] && b == mpY[pos[n-1].second])last = i; } vector<int> dp(n,0); for(int i = start;i <= last;i++){ int a,b,c; tie(a,b,c) = pos2[i]; if(i == start)dp[i] = 1; else dp[i] = sum(0,b+1); dp[i] %= mod; add(b,dp[i]); } cout << dp[last] << endl; }