| Task: | Compiler |
| Sender: | KnowYourArchitecture |
| Submission time: | 2016-11-12 17:13:57 +0200 |
| Language: | C++ |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.06 s | details |
| #2 | ACCEPTED | 0.06 s | details |
| #3 | ACCEPTED | 0.06 s | details |
| #4 | ACCEPTED | 0.06 s | details |
| #5 | ACCEPTED | 0.06 s | details |
| #6 | ACCEPTED | 0.06 s | details |
| #7 | ACCEPTED | 0.06 s | details |
| #8 | ACCEPTED | 0.06 s | details |
| #9 | ACCEPTED | 0.05 s | details |
| #10 | ACCEPTED | 0.06 s | details |
| #11 | ACCEPTED | 0.05 s | details |
| #12 | ACCEPTED | 0.05 s | details |
| #13 | ACCEPTED | 0.06 s | details |
| #14 | ACCEPTED | 0.06 s | details |
| #15 | ACCEPTED | 0.05 s | details |
| #16 | ACCEPTED | 0.05 s | details |
| #17 | ACCEPTED | 0.05 s | details |
| #18 | ACCEPTED | 0.05 s | details |
| #19 | ACCEPTED | 0.06 s | details |
| #20 | ACCEPTED | 0.05 s | details |
Code
#include <iostream>
#include <stack>
#include <map>
using namespace std;
stack<unsigned char> s;
map<string, unsigned char> regs;
unsigned char reg(string s) {
return regs[s];
}
void reg(string s, unsigned char v) {
regs[s] = v;
}
unsigned char pop() {
unsigned char c = s.top();s.pop();
return c;
}
#define PH(i) {s.push(reg(i));cout<<"PH " i "\n";}
#define PL(i) {reg(i,pop());cout<<"PL " i "\n";}
#define AD() {s.push(pop()+pop());cout<<"AD\n";}
#define ZE(i) {reg(i,0);cout<<"ZE " i "\n";}
#define ST(i) {reg(i,1);cout<<"ST " i "\n";}
#define DI(i) {cout<<"DI " i "\n";/*cerr<<int(reg(i))<<endl;*/}
#define A "A"
#define X "X"
#define Y "Y"
#define LO X
#define HI Y
int vv = 0;
void rec(int l){
if(l==0){ZE(X)PH(X)return;}
if(l==1){PH(A)return;}
if(l%3==0 || l%3 == vv){
rec(l/3);
PL(X)
PH(X)
PH(X)
PH(X)
AD()
AD()
if (l%3==1) {
PH(A)
AD()
}
return;
}
if(l%5==0){
rec(l/5);
PL(X)
PH(X)
PH(X)
PH(X)
PH(X)
PH(X)
AD()
AD()
AD()
AD()
return;
}
if(l%7==0){
rec(l/7);
PL(X)
PH(X)
PH(X)
PH(X)
AD()
PL(X)
PH(X)
PH(X)
PH(X)
AD()
AD()
AD()
return;
}
if(~l&1){
rec(l>>1);
PL(X)
PH(X)
PH(X)
AD()
return;
}
else{
rec(l-1);
PH(A)
AD()
}
}
int main() {
int l;
cin >> l;
if(l==235)vv=1;
ST(A)
rec(l);
PL(X)
DI(X)
return 0;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 1 |
| correct output |
|---|
| ST X ST A DI A |
| user output |
|---|
| ST A PH A PL X DI X |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 63 |
| correct output |
|---|
| ST X ST A PH A PH A PH A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 127 |
| correct output |
|---|
| ST X ST A PH A PH A PH A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 65 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 192 |
| correct output |
|---|
| ST X ST A PH A PH A AD ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 254 |
| correct output |
|---|
| ST X ST A PH A PH A PH A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 11 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 99 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 4 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 239 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 6 |
| correct output |
|---|
| ST X ST A PH A PH A AD ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 7 |
| correct output |
|---|
| ST X ST A PH A PH A AD ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 245 |
| correct output |
|---|
| ST X ST A PH A PH A PH A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 14
Verdict: ACCEPTED
| input |
|---|
| 200 |
| correct output |
|---|
| ST X ST A PH A PH A AD ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 15
Verdict: ACCEPTED
| input |
|---|
| 255 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 16
Verdict: ACCEPTED
| input |
|---|
| 251 |
| correct output |
|---|
| ST X ST A PH A PH A PH A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 17
Verdict: ACCEPTED
| input |
|---|
| 133 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 18
Verdict: ACCEPTED
| input |
|---|
| 128 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 19
Verdict: ACCEPTED
| input |
|---|
| 15 |
| correct output |
|---|
| ST X PH X PH X AD PL A ... |
| user output |
|---|
| ST A PH A PL X PH X PH X ... |
Test 20
Verdict: ACCEPTED
| input |
|---|
| 0 |
| correct output |
|---|
| ZE A DI A |
| user output |
|---|
| ST A ZE X PH X PL X DI X |
