結果
問題 |
No.265 数学のテスト
|
ユーザー |
|
提出日時 | 2015-08-07 23:48:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,448 bytes |
コンパイル時間 | 594 ms |
コンパイル使用メモリ | 62,796 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-18 05:26:27 |
合計ジャッジ時間 | 4,331 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 5 WA * 9 RE * 18 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <string> using namespace std; int n, d; string s; int getDegree(int idx) { if (s[idx] != 'x') { return 0; } int degree = 1; while(idx < n - 2) { if (s[idx + 1] == '*' && s[idx + 2] == 'x') { degree++; idx += 2; } else { break; } } return degree; } int main() { cin >> n >> d; cin >> s; s += "+"; vector<int> coefficient(d + 1, 0); n = s.size(); int depth = 0; int product = 1; int degree = 0; for (int i = 0; i < n; i++) { // printf("i %d %c\n", i, s[i]); if (isdigit(s[i])) { product = s[i] - '0'; if (s[i + 1] == '*') { i++; continue; } } else if (s[i] == 'd') { i++; // { depth++; } else if (s[i] == 'x') { int degree_now = getDegree(i); degree = degree_now - depth; if (degree >= 0) { for (int i = 0; i < depth; i++) { product *= degree_now - i; } } else { product *= 0; } // printf("degrees %d %d %d\n", degree, degree_now, product); i += (degree_now - 1) * 2; continue; } else { // + } if (s[i] == '}') { depth--; } if (isdigit(s[i - 1]) || s[i - 1] == 'x') { // printf("add %d %d\n", degree, product); coefficient[degree] += product; product = 1; } } } for (int i = 0; i <= d; i++) { cout << coefficient[i]; if (i != d) { cout << " "; } else { cout << endl; } } return 0; }