ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1495. One-two, One-two 2

WA #15... I just don't understand what is wrong with my program.... Help me pls!
Posted by intueor 9 Feb 2014 18:06
Just give me some hint pls: intueor19@gmail.com
I really don't understand what is wrong... It passes all tests on that forum but still has WA15

#include <iostream>
#include <vector>

using namespace std;

vector < int > pm (30, 0);
vector < vector < char > > d (31, vector < char > (1000000, 0));
int n;

void printAnswer (int, int);

int main () {
    cin >> n;

    pm[0] = 1 % n;
    for (int i = 1; i < 30; ++i)
        pm[i] = (pm[i - 1] * (10 % n)) % n;

    d[0][0] = 1;
    char found = 0;

    for (int i = 1; i <= 30; ++i) {
        int m1 = pm[i - 1];
        int m2 = ((2 % n) * pm[i - 1]) % n;

        if (d[i - 1][(n - m1) % n] != 0) {
            printAnswer (1, i);
            found = 1;
            break;
        }

        if (d[i - 1][(n - m2) % n] != 0) {
            printAnswer (2, i);
            found = 1;
            break;
        }

        for (int j = 0; j < n; ++j) {
            if (d[i - 1][j] == 0)
                continue;

            d[i][(j + m2) % n] = 2;
            d[i][(j + m1) % n] = 1;
        }
    }

    if (!found)
        cout << "Impossible";

    return 0;
}


void printAnswer (int digit, int lvl) {
    int k = 0;
    int x, j;

    while (lvl != 0) {
        cout << (int)digit;
        j = ((digit % n) * pm[lvl - 1]) % n;
        x = (k >= j) ? (k - j) : (n - j + k);
        digit = d[lvl - 1][x];
        k = x;
        --lvl;
    }

    return;
}

I got AC with other code but I still don't understand what's wrong with this one. Help me PLS!!!

Edited by author 09.02.2014 19:37