結果

問題 No.346 チワワ数え上げ問題
ユーザー yuppe19 😺yuppe19 😺
提出日時 2016-02-27 22:13:20
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 771 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 51,580 KB
最終ジャッジ日時 2024-04-27 02:17:53
合計ジャッジ時間 800 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:11:1: error: ‘vector’ does not name a type
   11 | vector<vector<i64>> nCr;
      | ^~~~~~
main.cpp: In function ‘int main()’:
main.cpp:18:3: error: ‘vector’ was not declared in this scope
   18 |   vector<int> ws(n, 0); // ws[n]
      |   ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
main.cpp:18:10: error: expected primary-expression before ‘int’
   18 |   vector<int> ws(n, 0); // ws[n]
      |          ^~~
main.cpp:19:5: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
   19 |   ws[0] = s[0]=='w';
      |     ^
main.cpp:21:7: error: invalid types ‘<unresolved overloaded function type>[long long int]’ for array subscript
   21 |     ws[i] = ws[i-1] + (s[i]=='w');
      |       ^
main.cpp:21:15: error: invalid types ‘<unresolved overloaded function type>[long long int]’ for array subscript
   21 |     ws[i] = ws[i-1] + (s[i]=='w');
      |               ^
main.cpp:26:20: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
   26 |       res += nC2(ws[n-1] - ws[i]);
      |                    ^
main.cpp:26:30: error: invalid types ‘<unresolved overloaded function type>[long long int]’ for array subscript
   26 |       res += nC2(ws[n-1] - ws[i]);
      |                              ^

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;

template<typename T>
class Range{private:struct I{T x;T operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:Range(T n):i({0}),n({n}){}Range(T i,T n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
using range = Range<i64>;

vector<vector<i64>> nCr;

i64 nC2(i64 n) { return n * (n-1) / 2; }

int main(void) {
  string s; cin >> s;
  int n = s.size();
  vector<int> ws(n, 0); // ws[n]
  ws[0] = s[0]=='w';
  for(auto&& i : range(1, n)) {
    ws[i] = ws[i-1] + (s[i]=='w');
  }
  i64 res = 0;
  for(auto&& i : range(n-1)) {
    if(s[i]=='c') {
      res += nC2(ws[n-1] - ws[i]);
    }
  }
  printf("%lld\n", res);
  return 0;
}
0