結果
問題 | No.265 数学のテスト |
ユーザー | Lepton_s |
提出日時 | 2015-08-07 23:03:52 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 856 ms / 2,000 ms |
コード長 | 1,453 bytes |
コンパイル時間 | 792 ms |
コンパイル使用メモリ | 86,360 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-11-24 11:18:22 |
合計ジャッジ時間 | 4,295 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <sstream> #include <functional> #include <map> #include <string> #include <cstring> #include <vector> #include <queue> #include <stack> #include <deque> #include <set> #include <list> #include <numeric> using namespace std; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const int INF = 1<<25; typedef pair<int,int> P; typedef long long ll; typedef unsigned long long ull; int n, d; string s; void expr(int l, int r, vector<long>& a); void term(int l, int r, vector<long>& a); void expr(int l, int r, vector<long>& a){ int p = 0; for(int i = l; i <= r; i++){ if(i==r || (p==0 && s[i]=='+')){ vector<long> a2(d+1, 0); term(l, i, a2); l = i+1; for(int j = 0; j <= d; j++) a[j] += a2[j]; } if(i==r) return; if(s[i]=='{') p++; if(s[i]=='}') p--; } } void term(int l, int r, vector<long>& a){ if(s[l]=='d'){ vector<long> a2(d+1, 0); expr(l+2, r-1, a2); for(int k = 1; k <= d; k++) a2[k-1] = k*a2[k]; a2[d] = 0; for(int j = 0; j <= d; j++) a[j] += a2[j]; return; } int cnst = 1, deg = 0; for(int i = l; i < r; i+=2){ if(s[i]=='x') deg++; else cnst = s[i]-'0'; } a[deg] += cnst; } int main(){ cin>>n>>d>>s; vector<long> a(d+1, 0); n = s.size(); expr(0, n, a); for(int i = 0; i <= d; i++) printf("%ld%c",a[i],i==d?'\n':' '); return 0; }