#include <iostream> #include <list> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; int *c; int *d; int i, j, k, e; int mini, maxi; int *maxk; long long *cnt; //cout << 1 << endl; cin >> n; c = new int[n]; d = new int[n]; maxk = new int[n+1]; cnt = new long long[n+1]; for (i = 0; i <= n; ++i) maxk[i] = 0; cnt[0] = 1; for (i = 0; i < n; ++i) { cin >> c[i] >> d[i]; } //cout << 1.5 << endl; for (i = 0; i < n; ++i) { if (cnt[i] > 0) { mini = 0; maxi = n+1; for (j = 0; i+j < n; ++j) { e = j + 1; if (maxi < e) break; k = i + j; mini = max(mini, c[k]); maxi = min(maxi, d[k]); if (mini <= e && e <= maxi) { if (maxk[k+1] < maxk[i]+1) { maxk[k+1] = maxk[i]+1; cnt[k+1] = cnt[i]; } else if (maxk[k+1] == maxk[i]+1) { cnt[k+1] += cnt[i]; cnt[k+1] %= 1000000007; } } } } } //cout << 2 << endl; /* for (i = 0; i < n; ++i) { for (list<int>::iterator it = g[i].begin(); it != g[i].end(); ++it) cout << (*it)+1 << ' '; cout << endl; } */ //for (i = 0; i <= n; ++i) cout << maxk[i] << ' ' << cnt[i] << endl; if (maxk[n] > 0) cout << maxk[n] << ' ' << cnt[n] << '\n'; else cout << "NIE\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include <iostream> #include <list> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; int *c; int *d; int i, j, k, e; int mini, maxi; int *maxk; long long *cnt; //cout << 1 << endl; cin >> n; c = new int[n]; d = new int[n]; maxk = new int[n+1]; cnt = new long long[n+1]; for (i = 0; i <= n; ++i) maxk[i] = 0; cnt[0] = 1; for (i = 0; i < n; ++i) { cin >> c[i] >> d[i]; } //cout << 1.5 << endl; for (i = 0; i < n; ++i) { if (cnt[i] > 0) { mini = 0; maxi = n+1; for (j = 0; i+j < n; ++j) { e = j + 1; if (maxi < e) break; k = i + j; mini = max(mini, c[k]); maxi = min(maxi, d[k]); if (mini <= e && e <= maxi) { if (maxk[k+1] < maxk[i]+1) { maxk[k+1] = maxk[i]+1; cnt[k+1] = cnt[i]; } else if (maxk[k+1] == maxk[i]+1) { cnt[k+1] += cnt[i]; cnt[k+1] %= 1000000007; } } } } } //cout << 2 << endl; /* for (i = 0; i < n; ++i) { for (list<int>::iterator it = g[i].begin(); it != g[i].end(); ++it) cout << (*it)+1 << ' '; cout << endl; } */ //for (i = 0; i <= n; ++i) cout << maxk[i] << ' ' << cnt[i] << endl; if (maxk[n] > 0) cout << maxk[n] << ' ' << cnt[n] << '\n'; else cout << "NIE\n"; } |