結果
問題 | No.265 数学のテスト |
ユーザー | Kmcode1 |
提出日時 | 2015-08-07 22:56:42 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,801 bytes |
コンパイル時間 | 964 ms |
コンパイル使用メモリ | 110,916 KB |
実行使用メモリ | 20,864 KB |
最終ジャッジ日時 | 2024-07-18 05:14:02 |
合計ジャッジ時間 | 1,922 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
20,864 KB |
testcase_01 | AC | 17 ms
12,544 KB |
testcase_02 | WA | - |
testcase_03 | AC | 4 ms
6,940 KB |
testcase_04 | AC | 4 ms
6,944 KB |
testcase_05 | WA | - |
testcase_06 | AC | 5 ms
6,940 KB |
testcase_07 | AC | 5 ms
6,944 KB |
testcase_08 | WA | - |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | WA | - |
testcase_11 | AC | 4 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 3 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,944 KB |
testcase_15 | AC | 1 ms
6,944 KB |
testcase_16 | WA | - |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | AC | 3 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 1 ms
6,940 KB |
testcase_29 | AC | 1 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 1 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 2 ms
6,940 KB |
testcase_35 | AC | 1 ms
6,940 KB |
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<vector> #include<list> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<sstream> #include<fstream> #include<iomanip> #include<ctime> #include<complex> #include<functional> #include<climits> #include<cassert> #include<iterator> #include<unordered_map> using namespace std; int n; int d; string s; #define MAX 50002 int be[MAX]; string pluss(string a, string b, bool flag = false){ if (!flag){ reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); } if (a.size() > b.size()){ swap(a, b); } string ans; ans.clear(); long long int want = 0; for (int i = 0; i < a.size(); i++){ long long int val = a[i] - '0'; val += b[i] - '0'; val += want; want = val / 10LL; val %= 10LL; ans.push_back(val + '0'); } for (int j = a.size(); j < b.size(); j++){ long long int val = 0; val += b[j] - '0'; val += want; want = val / 10LL; val %= 10LL; ans.push_back(val + '0'); } while (want){ ans.push_back(want % 10 + '0'); want /= 10; } if (!flag){ reverse(ans.begin(), ans.end()); } return ans; } string mult(string a, string b, bool flag = false){ if (!flag){ reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); } string ans = "0"; string pas; string kari; pas.clear(); for (int i = 0; i < b.size(); i++){ long long int bb = b[i] - '0'; long long int tmp = 0; kari = pas; for (int j = 0; j < a.size(); j++){ long long int val = (long long int)(a[j] - '0')*bb; val += tmp; tmp = val / 10LL; val %= 10LL; kari.push_back(val + '0'); } while (tmp){ kari.push_back((tmp % 10LL) + '0'); tmp /= 10LL; } ans = pluss(ans, kari, true); //end pas.push_back('0'); } if (!flag){ reverse(ans.begin(), ans.end()); } return ans; } string zero = "0"; vector<string> v; string kari; struct st{ string ind[12]; st(){ for (int i = 0; i < 12; i++){ ind[i] = zero; } } void mult_x(int num=1){ for (int i = 10; i >= 0; i--){ if (i + num < 12){ ind[i + num] = ind[i]; } } } void mult_val(string num){ for (int i = 0; i <= 10; i++){ if (ind[i] != zero){ ind[i] = mult(ind[i], num); } } } st ex(){ for (int i = 1; i <= 10; i++){ ind[i - 1] = ind[i]; ind[i - 1] = mult(ind[i - 1], v[i]); } return *this; } void output(){ for (int i = 0; i <= d; i++){ if (i){ printf(" "); } printf("%s", ind[i].c_str()); } } void merge(st a){ for (int i = 0; i <= d; i++){ ind[i] = pluss(ind[i], a.ind[i]); } } void add(int id, string val){ ind[id] = pluss(ind[id], val); } }; inline st dfs(int l,int r){ st R; int countt = 0; string val = "1"; bool flag = false; while (l <= r){ if (s[l] == '}' || s[l] == '+'){ if (flag){ R.add(countt, val); val = "1"; countt = 0; flag = false; } l++; continue; } if (s[l] == '{'){ l++; continue; } if (s[l] == 'd'){ if (flag){ exit(1); } R.merge(dfs(l + 2, be[l]).ex()); l = be[l] + 1; continue; } if (s[l] == '*'){ l++; continue; } if (isdigit(s[l])){ flag = true; val = mult(val, v[s[l] - '0']); l++; continue; } if (s[l] == 'x'){ flag = true; countt++; l++; continue; } } if (flag){ R.add(countt, val); } return R; } int main(){ for (int i = 0; i <= 10; i++){ kari.clear(); kari.push_back(i + '0'); v.push_back(kari); } cin >> n >> d; cin >> s; stack<int> st; for (int i = 0; i < s.size(); i++){ if (s[i] == 'd'){ st.push(i); } if (s[i]=='}'){ be[st.top()] = i; st.pop(); } } if (st.size()){ return 1; } dfs(0, s.size() - 1).output(); puts(""); return 0; }