0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

もうちょっとで解けそうだったなEF問題集

Last updated at Posted at 2020-05-03

はじめに

間に合わなかったけど,時間があれば解けたなという問題集です.Eわからず調子に乗ってFに挑戦した結果,両方落としがちなので反省のために...
いつも使ってるヘッダーは以下です(好みはあると思います).

# include <bits/stdc++.h>
# define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
# define rep(i, n) FOR(i, 0, n)
using ll = long long;
using ull = unsigned long long;
using namespace std;
# define all(x) (x).begin(),(x).end()
# define rall(x) (x).rbegin(),(x).rend()
using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>;
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }

ACC166-E

$b_i=a_i-i$, $c_i=-a_i-i$とすると$a_i+a_j=i-j \Leftrightarrow b_i=c_j$なので,$b_i=c_j$かつ$i \neq j$なる数を数えればいい.

# define int long long // をヘッダーに挟み込む
int n;
signed main() {
    cin>>n;
    vi a(n);
    rep(i,n) cin>>a[i];
    vi b(a), c(n);
    rep(i,n) b[i] -= i;
    rep(i,n) c[i] = -a[i] - i;
    int ans = 0;
    unordered_map<int, int> m;
    rep(i,n) {
        m[b[i]]++;
    }
    rep(j,n) {
        if(b[j]!=c[j])
            ans += m[c[j]];
        else
            ans += m[c[j]] - 1;
    }
    
    cout<<ans<<endl;
    return 0;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?