結果
問題 | No.265 数学のテスト |
ユーザー | Kmcode1 |
提出日時 | 2015-08-07 22:59:28 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,875 bytes |
コンパイル時間 | 1,218 ms |
コンパイル使用メモリ | 110,436 KB |
実行使用メモリ | 21,120 KB |
最終ジャッジ日時 | 2024-07-18 05:14:59 |
合計ジャッジ時間 | 2,249 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
21,120 KB |
testcase_01 | AC | 20 ms
12,672 KB |
testcase_02 | WA | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 1 ms
5,376 KB |
testcase_35 | AC | 1 ms
5,376 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])){ if (flag){ exit(1); } flag = true; val = mult(val, v[s[l] - '0']); l++; continue; } if (s[l] == 'x'){ flag = true; countt++; l++; continue; } } if (flag){ if (r != s.size() - 1){ exit(1); } 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; }