結果

問題 No.1864 Shortest Paths Counting
ユーザー t_mkt_mk
提出日時 2022-03-15 20:26:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 914 ms / 2,000 ms
コード長 1,875 bytes
コンパイル時間 2,595 ms
コンパイル使用メモリ 194,748 KB
実行使用メモリ 54,184 KB
最終ジャッジ日時 2023-10-23 18:55:31
合計ジャッジ時間 21,343 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
19,508 KB
testcase_01 AC 7 ms
19,508 KB
testcase_02 AC 7 ms
19,508 KB
testcase_03 AC 7 ms
19,508 KB
testcase_04 AC 7 ms
19,508 KB
testcase_05 AC 7 ms
19,508 KB
testcase_06 AC 7 ms
19,508 KB
testcase_07 AC 7 ms
19,508 KB
testcase_08 AC 7 ms
19,508 KB
testcase_09 AC 785 ms
54,128 KB
testcase_10 AC 836 ms
54,128 KB
testcase_11 AC 815 ms
54,128 KB
testcase_12 AC 873 ms
54,128 KB
testcase_13 AC 817 ms
54,128 KB
testcase_14 AC 848 ms
54,128 KB
testcase_15 AC 808 ms
54,128 KB
testcase_16 AC 796 ms
54,128 KB
testcase_17 AC 822 ms
54,128 KB
testcase_18 AC 824 ms
54,128 KB
testcase_19 AC 855 ms
54,128 KB
testcase_20 AC 914 ms
54,128 KB
testcase_21 AC 873 ms
54,128 KB
testcase_22 AC 804 ms
54,128 KB
testcase_23 AC 804 ms
54,128 KB
testcase_24 AC 7 ms
19,508 KB
testcase_25 AC 587 ms
41,776 KB
testcase_26 AC 782 ms
54,184 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;
      |       ^~~~~

ソースコード

diff #

#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;
}
0