結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー MSKMSK
提出日時 2018-10-10 13:48:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,505 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 64,236 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-20 19:25:23
合計ジャッジ時間 7,682 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
10,624 KB
testcase_01 AC 15 ms
5,376 KB
testcase_02 AC 14 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int> M(N + 1);
  for(int i = 1; i <= N; i++) {
    cin >> M[i];
  }
  vector<int> V(N + 1, 0);
  for(int i = 1; i <= N; i++) {
    if(0 < M[i] - i) {
      V[i] = 1;
    } else if(0 > M[i] - i) {
      V[i] = -1;
    }
  }
  int maxt = 0;
  for(int i = 1; i <= N; i++) {
    maxt = max(maxt, abs(M[i] - i));
  }
  int ans = 0;
  for(int t = 1; t <= maxt; t++) {
    vector<int> NCatStay(30001, 0);
    vector<int> NCatComeFromL(30001, 0);
    vector<int> NCatComeFromR(30001, 0);
    cerr << t << endl;
    for(int i = 1; i <= N; i++) {
      if(0 == V[i]) {
        cerr << i << ' ' << M[i] << endl;
        NCatStay[M[i]]++;
      } else {
        int pos = i + V[i] * t;
        cerr << i << ' ' << pos << endl;
        if(V[i] > 0) {
          NCatComeFromL[pos]++;
        } else {
          NCatComeFromR[pos]++;
        }
        if(M[i] == pos) {
          V[i] = 0;
        }
      }
    }
    for(int i = 1; i < 100; i++) {
      int NCatCome = NCatComeFromL[i] + NCatComeFromR[i];
      ans += NCatStay[i] * NCatCome;
      ans += NCatCome * (NCatCome - 1) / 2;
      cerr << i << ' ' << NCatStay[i] << ' ' << NCatCome;
      if(i > 1) {
        ans += NCatComeFromR[i - 1] * NCatComeFromL[i];
        cerr << ' ' << NCatComeFromR[i - 1] << ' '
             << NCatComeFromL[i];
      }
      cerr << ' ' << ans << endl;
    }
  }
  cout << ans << endl;
  return 0;
}
0