京都大学プログラミングコンテスト2015

Submission #1592139

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

string a;
string ans;
deque<string> v;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a;
    int n = a.size();
    if (n == 1) {
        cout << a << endl;
        return 0;
    }
    vector<char> stack;
    int i = 0;
    while (i < n) {
        int cnt = 0;
        while (i < n && (a[i] == '+' || a[i] == '-' || a[i] == '*')) {
            int end = stack.size() - 1;
            string tmp;
            if (end == -1) {
                tmp += v[0];
                tmp += v[1];
                tmp += a[i];
                v.pop_front();
                v.pop_front();
                v.push_front(tmp);
            }
            else if (end == 0 && cnt == 0) {
                tmp += stack[end];  
                tmp += v[0];
                tmp += a[i];
                v.pop_front();
                v.push_front(tmp);
            }
            else {
                if (cnt == 0) {
                    tmp += stack[end];
                    tmp += stack[end - 1];
                    tmp += a[i];
                    cnt++;
                    stack.pop_back();
                    stack.pop_back();
                    v.push_front(tmp);
                }
                else {
                    tmp += v[0];
                    tmp += stack[end];
                    tmp += a[i];
                    v.pop_front();
                    stack.pop_back();
                    v.push_front(tmp);
                }
            }
            i++;
        }
        if (i == n) break;
        stack.push_back(a[i]);
        i++;
    }
    rep(i, v.size()) ans += v[i];
    cout << ans << endl;
}

Submission

Task問題 F - 逆ポーランド記法
User nameユーザ名 roto_37
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2894 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
All 0 / 200 00_sample_01.txt,00_sample_02.txt,10_random_all_01.txt,10_random_all_02.txt,10_random_all_03.txt,10_random_all_04.txt,10_random_all_05.txt,10_random_all_06.txt,10_random_all_07.txt,10_random_all_08.txt,10_random_all_09.txt,10_random_all_10.txt,10_random_all_11.txt,10_random_all_12.txt,10_random_all_13.txt,10_random_all_14.txt,10_random_all_15.txt,10_random_all_16.txt,10_random_all_17.txt,10_random_all_18.txt,10_random_all_19.txt,10_random_all_20.txt,10_random_all_21.txt,10_random_all_22.txt,10_random_all_23.txt,10_random_all_24.txt,10_random_all_25.txt,10_random_all_26.txt,10_random_all_27.txt,10_random_all_28.txt,10_random_all_29.txt,10_random_all_30.txt,10_random_all_31.txt,10_random_all_32.txt,10_random_all_33.txt,10_random_all_34.txt,10_random_all_35.txt,10_random_all_36.txt,10_random_all_37.txt,10_random_all_38.txt,10_random_all_39.txt,10_random_all_40.txt,10_random_all_41.txt,10_random_all_42.txt,10_random_all_43.txt,10_random_all_44.txt,10_random_all_45.txt,10_random_all_46.txt,10_random_all_47.txt,10_random_all_48.txt,10_random_all_49.txt,10_random_all_50.txt,22_small_51.txt,22_small_52.txt,22_small_53.txt,22_small_54.txt,22_small_55.txt,22_small_56.txt,22_small_57.txt,22_small_58.txt,22_small_59.txt,22_small_60.txt,22_small_61.txt,22_small_62.txt,22_small_63.txt,22_small_64.txt,22_small_65.txt,22_small_66.txt,22_small_67.txt,22_small_68.txt,22_small_69.txt,22_small_70.txt,33_alternation_71.txt,33_alternation_72.txt,33_alternation_73.txt,33_alternation_74.txt,33_alternation_75.txt,33_alternation_76.txt,33_alternation_77.txt,33_alternation_78.txt,33_alternation_79.txt,33_alternation_80.txt,34_oneside_81.txt,34_oneside_82.txt,34_oneside_83.txt,34_oneside_84.txt,34_oneside_85.txt,34_oneside_86.txt,34_oneside_87.txt,34_oneside_88.txt,34_oneside_89.txt,34_oneside_90.txt,44_mul_91.txt,44_mul_92.txt,44_mul_93.txt,44_mul_94.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01.txt AC 1 ms 256 KB
00_sample_02.txt AC 1 ms 256 KB
10_random_all_01.txt AC 1 ms 256 KB
10_random_all_02.txt AC 1 ms 256 KB
10_random_all_03.txt AC 1 ms 256 KB
10_random_all_04.txt WA
10_random_all_05.txt WA
10_random_all_06.txt WA
10_random_all_07.txt WA
10_random_all_08.txt WA
10_random_all_09.txt WA
10_random_all_10.txt WA
10_random_all_11.txt WA
10_random_all_12.txt WA
10_random_all_13.txt WA
10_random_all_14.txt WA
10_random_all_15.txt WA
10_random_all_16.txt WA
10_random_all_17.txt WA
10_random_all_18.txt WA
10_random_all_19.txt WA
10_random_all_20.txt WA
10_random_all_21.txt WA
10_random_all_22.txt WA
10_random_all_23.txt WA
10_random_all_24.txt WA
10_random_all_25.txt WA
10_random_all_26.txt WA
10_random_all_27.txt WA
10_random_all_28.txt WA
10_random_all_29.txt WA
10_random_all_30.txt WA
10_random_all_31.txt WA
10_random_all_32.txt WA
10_random_all_33.txt WA
10_random_all_34.txt WA
10_random_all_35.txt WA
10_random_all_36.txt WA
10_random_all_37.txt WA
10_random_all_38.txt WA
10_random_all_39.txt WA
10_random_all_40.txt WA
10_random_all_41.txt WA
10_random_all_42.txt WA
10_random_all_43.txt WA
10_random_all_44.txt WA
10_random_all_45.txt WA
10_random_all_46.txt WA
10_random_all_47.txt WA
10_random_all_48.txt WA
10_random_all_49.txt WA
10_random_all_50.txt WA
22_small_51.txt WA
22_small_52.txt WA
22_small_53.txt AC 1 ms 256 KB
22_small_54.txt WA
22_small_55.txt WA
22_small_56.txt AC 1 ms 256 KB
22_small_57.txt WA
22_small_58.txt WA
22_small_59.txt WA
22_small_60.txt WA
22_small_61.txt WA
22_small_62.txt WA
22_small_63.txt WA
22_small_64.txt WA
22_small_65.txt WA
22_small_66.txt AC 1 ms 256 KB
22_small_67.txt WA
22_small_68.txt WA
22_small_69.txt AC 1 ms 256 KB
22_small_70.txt AC 1 ms 256 KB
33_alternation_71.txt WA
33_alternation_72.txt WA
33_alternation_73.txt WA
33_alternation_74.txt WA
33_alternation_75.txt WA
33_alternation_76.txt WA
33_alternation_77.txt WA
33_alternation_78.txt WA
33_alternation_79.txt WA
33_alternation_80.txt WA
34_oneside_81.txt AC 1 ms 256 KB
34_oneside_82.txt AC 1 ms 256 KB
34_oneside_83.txt AC 1 ms 256 KB
34_oneside_84.txt AC 1 ms 256 KB
34_oneside_85.txt AC 1 ms 256 KB
34_oneside_86.txt AC 1 ms 256 KB
34_oneside_87.txt AC 1 ms 256 KB
34_oneside_88.txt AC 1 ms 256 KB
34_oneside_89.txt AC 1 ms 256 KB
34_oneside_90.txt AC 1 ms 256 KB
44_mul_91.txt WA
44_mul_92.txt WA
44_mul_93.txt AC 1 ms 256 KB
44_mul_94.txt AC 1 ms 256 KB