結果
問題 | No.265 数学のテスト |
ユーザー | Kmcode1 |
提出日時 | 2015-08-07 23:09:39 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,967 bytes |
コンパイル時間 | 970 ms |
コンパイル使用メモリ | 111,360 KB |
実行使用メモリ | 21,120 KB |
最終ジャッジ日時 | 2024-07-18 05:18:07 |
合計ジャッジ時間 | 1,997 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | WA | - |
testcase_17 | AC | 1 ms
6,944 KB |
testcase_18 | AC | 1 ms
6,944 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | WA | - |
testcase_26 | AC | 1 ms
6,944 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | WA | - |
testcase_29 | AC | 1 ms
6,940 KB |
testcase_30 | WA | - |
testcase_31 | AC | 1 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 1 ms
6,940 KB |
testcase_34 | AC | 1 ms
6,944 KB |
testcase_35 | AC | 2 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 = 11; i >= 0; i--){ if (i + num < 12){ ind[i + num] = ind[i]; } } } void mult_val(string num){ for (int i = 0; i <= 11; i++){ if (ind[i] != zero){ ind[i] = mult(ind[i], num); } } } st ex(){ for (int i = 1; i <= 11; 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 <= 11; 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; bool fll = false; while (l <= r){ if (s[l] == '}' || s[l] == '+'){ if (flag){ R.add(countt, val); val = "1"; countt = 0; flag = false; fll = 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])){ fll = true; 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 <= 11; i++){ kari.clear(); kari.push_back(i + '0'); if (i == 10){ kari = "10"; } if (i == 11){ kari = "11"; } 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; }