#2330451

Solution for 2613: Unordered Operators by noy72

Source Code Status Test Cases
    Policy: public     Reviewed: 16    
00.00 sec    3232 KB    149 lines     3936 bytes    2017-05-22 08:53
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

typedef string::const_iterator State;
long long number(State&);
long long factor(State&,vector<long long>);
long long expr3(State&,long long,vector<long long>);
long long expr2(State&,long long,vector<long long>);
long long expr1(State&,long long,vector<long long>);

vector<vector<long long>> v;

// ??°??????????????????????????????????????°????????????
long long number(State &begin) {
    long long ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
long long factor(State &begin, vector<long long> v) {
    if (*begin == '(') {
        begin++; // '('????£???°??????
        long long ret = expr1(begin,0,v);
        begin++; // ')'????£???°??????
        return ret;
    } else {
        return number(begin);
    }
    return 0;
}

long long expr3(State &begin, long long i, vector<long long> v) {
    long long ret = factor(begin,v);

    for (;;) {
        if (*begin == '+' && v[i] & 1) {
            begin++;
            ret += factor(begin,v);
        } else if (*begin == '-' && v[i] & 2) {
            begin++;
            ret -= factor(begin,v);
        } else if (*begin == '*' && v[i] & 4){
            begin++;
            ret *= factor(begin,v);
        } else {
            break;
        }
    }

    return ret;
}

long long expr2(State &begin, long long i, vector<long long> v) {
    long long ret = expr3(begin, 2, v);

    for (;;) {
        if (*begin == '+' && v[i] & 1) {
            begin++;
            ret += expr3(begin, 2, v);
        } else if (*begin == '-' && v[i] & 2) {
            begin++;
            ret -= expr3(begin, 2, v);
        } else if (*begin == '*' && v[i] & 4){
            begin++;
            ret *= expr3(begin, 2, v);
        } else {
            break;
        }

    }

    return ret;
}

long long expr1(State &begin, long long i, vector<long long> v) {
    long long ret = expr2(begin, 1, v);

    for (;;) {
        if (*begin == '+' && v[i] & 1) {
            begin++;
            ret += expr2(begin, 1, v);
        } else if (*begin == '-' && v[i] & 2) {
            begin++;
            ret -= expr2(begin, 1, v);
        } else if (*begin == '*' && v[i] & 4){
            begin++;
            ret *= expr2(begin, 1, v);
        } else {
            break;
        }

    }

    return ret;
}



//begin???expected?????????????????????begin?????????????????????
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'" << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        //throw ParseError();
    }
}

int main(){
    vector<long long> num = {1,2,4};
    do{ v.emplace_back(num); }while(next_permutation(all(num))); 
    num = {0,3,4};
    do{ v.emplace_back(num); }while(next_permutation(all(num))); 
    num = {0,5,2};
    do{ v.emplace_back(num); }while(next_permutation(all(num))); 
    num = {0,6,1};
    do{ v.emplace_back(num); }while(next_permutation(all(num))); 
    num = {0,0,7};
    do{ v.emplace_back(num); }while(next_permutation(all(num))); 

    string s;
    cin >> s;

    long long ans = -LONG_MAX;
    rep(i,v.size()){
        State tmp = s.begin();
        ans = max(ans, expr1(tmp, 0, v[i]));
        assert(tmp == s.end());
    }
    cout << ans << endl;
}


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 119/119 C++11 CPU: 00.00 sec Memory: 3232 KB Length: 3936 B 2017-05-22 08:53 2017-05-22 08:53
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.00 sec 3152 KB
Case #2: : Accepted 00.00 sec 3152 KB
Case #3: : Accepted 00.00 sec 3084 KB
Case #4: : Accepted 00.00 sec 3184 KB
Case #5: : Accepted 00.00 sec 3164 KB
Case #6: : Accepted 00.00 sec 3016 KB
Case #7: : Accepted 00.00 sec 3176 KB
Case #8: : Accepted 00.00 sec 3228 KB
Case #9: : Accepted 00.00 sec 3016 KB
Case #10: : Accepted 00.00 sec 3164 KB
Case #11: : Accepted 00.00 sec 3152 KB
Case #12: : Accepted 00.00 sec 3228 KB
Case #13: : Accepted 00.00 sec 3080 KB
Case #14: : Accepted 00.00 sec 3000 KB
Case #15: : Accepted 00.00 sec 3000 KB
Case #16: : Accepted 00.00 sec 3088 KB
Case #17: : Accepted 00.00 sec 3164 KB
Case #18: : Accepted 00.00 sec 3016 KB
Case #19: : Accepted 00.00 sec 3108 KB
Case #20: : Accepted 00.00 sec 3172 KB
Case #21: : Accepted 00.00 sec 3108 KB
Case #22: : Accepted 00.00 sec 3180 KB
Case #23: : Accepted 00.00 sec 3188 KB
Case #24: : Accepted 00.00 sec 3000 KB
Case #25: : Accepted 00.00 sec 3108 KB
Case #26: : Accepted 00.00 sec 3148 KB
Case #27: : Accepted 00.00 sec 3188 KB
Case #28: : Accepted 00.00 sec 3176 KB
Case #29: : Accepted 00.00 sec 3188 KB
Case #30: : Accepted 00.00 sec 3000 KB
Case #31: : Accepted 00.00 sec 3064 KB
Case #32: : Accepted 00.00 sec 3060 KB
Case #33: : Accepted 00.00 sec 3016 KB
Case #34: : Accepted 00.00 sec 3088 KB
Case #35: : Accepted 00.00 sec 3144 KB
Case #36: : Accepted 00.00 sec 3148 KB
Case #37: : Accepted 00.00 sec 3108 KB
Case #38: : Accepted 00.00 sec 3232 KB
Case #39: : Accepted 00.00 sec 3000 KB
Case #40: : Accepted 00.00 sec 3088 KB
Case #41: : Accepted 00.00 sec 3016 KB
Case #42: : Accepted 00.00 sec 3188 KB
Case #43: : Accepted 00.00 sec 3060 KB
Case #44: : Accepted 00.00 sec 3152 KB
Case #45: : Accepted 00.00 sec 3144 KB
Case #46: : Accepted 00.00 sec 3088 KB
Case #47: : Accepted 00.00 sec 3084 KB
Case #48: : Accepted 00.00 sec 3176 KB
Case #49: : Accepted 00.00 sec 3164 KB
Case #50: : Accepted 00.00 sec 3088 KB
Case #51: : Accepted 00.00 sec 3088 KB
Case #52: : Accepted 00.00 sec 3176 KB
Case #53: : Accepted 00.00 sec 3060 KB
Case #54: : Accepted 00.00 sec 3176 KB
Case #55: : Accepted 00.00 sec 3148 KB
Case #56: : Accepted 00.00 sec 3016 KB
Case #57: : Accepted 00.00 sec 3072 KB
Case #58: : Accepted 00.00 sec 3176 KB
Case #59: : Accepted 00.00 sec 3228 KB
Case #60: : Accepted 00.00 sec 3020 KB
Case #61: : Accepted 00.00 sec 3152 KB
Case #62: : Accepted 00.00 sec 3176 KB
Case #63: : Accepted 00.00 sec 3088 KB
Case #64: : Accepted 00.00 sec 3188 KB
Case #65: : Accepted 00.00 sec 3128 KB
Case #66: : Accepted 00.00 sec 3000 KB
Case #67: : Accepted 00.00 sec 3016 KB
Case #68: : Accepted 00.00 sec 3072 KB
Case #69: : Accepted 00.00 sec 3020 KB
Case #70: : Accepted 00.00 sec 3172 KB
Case #71: : Accepted 00.00 sec 3108 KB
Case #72: : Accepted 00.00 sec 3164 KB
Case #73: : Accepted 00.00 sec 3108 KB
Case #74: : Accepted 00.00 sec 3188 KB
Case #75: : Accepted 00.00 sec 3172 KB
Case #76: : Accepted 00.00 sec 3060 KB
Case #77: : Accepted 00.00 sec 3072 KB
Case #78: : Accepted 00.00 sec 3060 KB
Case #79: : Accepted 00.00 sec 3164 KB
Case #80: : Accepted 00.00 sec 3152 KB
Case #81: : Accepted 00.00 sec 3000 KB
Case #82: : Accepted 00.00 sec 3076 KB
Case #83: : Accepted 00.00 sec 3084 KB
Case #84: : Accepted 00.00 sec 3188 KB
Case #85: : Accepted 00.00 sec 3172 KB
Case #86: : Accepted 00.00 sec 3004 KB
Case #87: : Accepted 00.00 sec 3124 KB
Case #88: : Accepted 00.00 sec 3172 KB
Case #89: : Accepted 00.00 sec 3108 KB
Case #90: : Accepted 00.00 sec 3076 KB
Case #91: : Accepted 00.00 sec 3184 KB
Case #92: : Accepted 00.00 sec 3192 KB
Case #93: : Accepted 00.00 sec 3000 KB
Case #94: : Accepted 00.00 sec 3104 KB
Case #95: : Accepted 00.00 sec 3228 KB
Case #96: : Accepted 00.00 sec 3084 KB
Case #97: : Accepted 00.00 sec 3128 KB
Case #98: : Accepted 00.00 sec 3088 KB
Case #99: : Accepted 00.00 sec 3088 KB
Case #100: : Accepted 00.00 sec 3004 KB
Case #101: : Accepted 00.00 sec 3128 KB
Case #102: : Accepted 00.00 sec 3084 KB
Case #103: : Accepted 00.00 sec 3016 KB
Case #104: : Accepted 00.00 sec 3188 KB
Case #105: : Accepted 00.00 sec 3132 KB
Case #106: : Accepted 00.00 sec 3188 KB
Case #107: : Accepted 00.00 sec 3164 KB
Case #108: : Accepted 00.00 sec 3168 KB
Case #109: : Accepted 00.00 sec 3172 KB
Case #110: : Accepted 00.00 sec 3072 KB
Case #111: : Accepted 00.00 sec 3188 KB
Case #112: : Accepted 00.00 sec 3092 KB
Case #113: : Accepted 00.00 sec 3060 KB
Case #114: : Accepted 00.00 sec 3228 KB
Case #115: : Accepted 00.00 sec 3152 KB
Case #116: : Accepted 00.00 sec 3088 KB
Case #117: : Accepted 00.00 sec 3072 KB
Case #118: : Accepted 00.00 sec 3016 KB
Case #119: : Accepted 00.00 sec 3128 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags