Submission #127106

#TimeUsernameProblemLanguageResultExecution timeMemory
127106eriksuenderhaufTeams (CEOI11_tea)C++11
100 / 100
568 ms74872 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #define enl printf("\n") #define case(t) printf("Case #%d: ", (t)) #define ni(n) scanf("%d", &(n)) #define nl(n) scanf("%I64d", &(n)) #define nai(a, n) for (int i = 1; i <= (n); i++) ni(a[i]) #define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i]) #define pri(n) printf("%d\n", (n)) #define prl(n) printf("%I64d\n", (n)) #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<pii> #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; const double pi = acos(-1); const int MOD = 1e9 + 7; const int INF = 1e9 + 7; const int MAXN = 2e6 + 5; const double eps = 1e-9; pii a[MAXN]; int tree[MAXN], pre[MAXN], ans[MAXN]; int dp[MAXN], n, par[MAXN]; int solve(int x) { memset(tree, 0, sizeof tree); tree[0] = 1; for (int i =1; i <= n; i++) { if (i < a[i].fi) dp[i] = -INF; else { dp[i] = pre[i - a[i].fi] + 1; if (ans[i - a[i].fi] >= i - x) tree[i] = 1, par[i] = ans[i - a[i].fi]; } pre[i] = pre[i - 1]; ans[i] = ans[i - 1]; if (tree[i] && pre[i] <= dp[i]) ans[i] = i, pre[i] = dp[i]; } return tree[n]; } void dfs(int u) { if (u == 0) return; dfs(par[u]); printf("%d ", u - par[u]); for (int i = par[u] + 1; i <= u; i++) printf("%d ", a[i].se); enl; } int main() { ni(n); for (int i = 1; i <= n;i ++) ni(a[i].fi), a[i].se = i; sort(a + 1, a + n + 1); int lo = 1, hi = n; int sz = n; while (lo != hi) { int mi = (lo + hi) / 2; if (solve(mi)) hi = mi; else lo = mi + 1; } solve(lo); pri(dp[n]); dfs(n); return 0; }

Compilation message (stderr)

tea.cpp: In function 'int main()':
tea.cpp:70:9: warning: unused variable 'sz' [-Wunused-variable]
     int sz = n;
         ^~
tea.cpp:5:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
tea.cpp:65:5: note: in expansion of macro 'ni'
     ni(n);
     ^~
tea.cpp:67:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         ni(a[i].fi), a[i].se = i;
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...