|
|
вернуться в форумWA #15... I just don't understand what is wrong with my program.... Help me pls! 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 |
|
|