제출 #1269524

#제출 시각아이디문제언어결과실행 시간메모리
1269524Bui_Quoc_CuongUzastopni (COCI15_uzastopni)C++20
0 / 160
4 ms840 KiB
#include <bits/stdc++.h> using namespace std; // #define int long long typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; template<class T> bool minimize(T &a, const T &b) { if (a > b) return a = b, true; return false; } template<class T> bool maximize(T &a, const T &b) { if (a < b) return a = b, true; return false; } #define FOR(i, a, b) for (int i = a; i <= (int)b; i++) #define FORD(i, a, b) for (int i = a; i >= (int)b; i--) #define MASK(i) (1LL << (i)) #define BIT(S, i) (((S) >> (i)) & 1) #define mp make_pair #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() const int N = 5e5 + 5; int n, m; int a[N]; vector <int> g[N]; void init(void) { cin >> n >> m; FOR(i, 1, n) cin >> a[i]; FOR(i, 1, n - 1) { int u, v; cin >> u >> v; g[u].push_back(v); } } bitset <105> dp[10005][105]; bitset <105> f[105]; void dfs(int u) { for (int &v : g[u]) dfs(v); FOR(i, 1, m) f[i].reset(); f[a[u]][a[u]] = 1; for (int &v : g[u]) { FOR(i, 1, m) f[i] |= dp[v][i]; } FOR(i, 1, m) FOR(j, i, m) if (f[i][j]) f[i] |= f[j + 1]; dp[u][a[u]][a[u]] = 1; FOR(i, 1, m) FOR(j, i, m) { if (i == a[u] && f[i + 1][j]) dp[u][i][j] = 1; else if (j == a[u] && f[i][j - 1]) dp[u][i][j] = 1; else if (f[i][a[u] - 1] && f[a[u] + 1][j]) dp[u][i][j] = 1; } } void process(void) { dfs(1); int ans = 0; FOR(i, 1, m) FOR(j, i, m) if (dp[1][i][j]) ans++; cout << ans; } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); #define taskname "uzastopni" if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } init(); process(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

uzastopni.cpp: In function 'int main()':
uzastopni.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
uzastopni.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...