제출 #1006793

#제출 시각아이디문제언어결과실행 시간메모리
1006793RifalLongest beautiful sequence (IZhO17_subsequence)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
#include <fstream>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define mod 1000000007
#define INF 1000000000
#define INF2 2000000000
#define fi first
#define se second
using namespace std;
double const EPS = 1e-14;
const int P = 1007;
typedef long long ll;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
int cnt(int val) {
    int tot = 0;
    for(int i = 0; i < 21; i++) {
        if((val&(1<<i)) > 0) tot++;
    }
    return tot;
}
int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int n; cin >> n; int arr[n], k[n]; int dp[n+1][n+1] = {};
    pair<int,int> next[n+1][n+1], ans = {};
    for(int i = 1; i <= n; i++) dp[0][i] = 1;
    for(int i = 1; i <= n; i++) cin >> arr[i];
    for(int i = 1; i <= n; i++) cin >> k[i];
    for(int i = 1; i <= n; i++) {
        for(int j = i-1; j >= 1; j--) {
            for(int z = j-1; z >= 0; z--) {
                if(dp[j][z] != 0 && cnt(arr[i]&arr[j]) == k[i]) {
                    if(dp[i][j]  <  dp[j][z]+1) {
                    dp[i][j] = max(dp[i][j],dp[j][z]+1);
                    ans.fi = i;
                    ans.se = j;
                    next[i][j].fi = j;
                    next[i][j].se = z;
                    } 
                }
            }
        }
    }
    if(ans.fi == 0) {
        cout << 1 << endl;
        cout << 1 << endl;
    }
    else {
        vector<int> order;
        while(ans.fi != 0) {
            order.push_back(ans.fi);
            ans.fi = next[ans.fi].fi;
            ans.se = next[ans.se].se;
        }
        cout << order.size() << endl;
        for(int i = order.size()-1; i >= 0; i--) cout << order[i] << ' ';
        cout << endl;
    }
}
/*7 1 4        
3 3 3 4 4 2 1
2 4
6 7
4 7
1 4
2
0
2
2*/

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:9:12: error: request for member 'first' in 'next[ans.std::pair<int, int>::first]', which is of non-class type 'std::pair<int, int> [(n + 1)]'
    9 | #define fi first
      |            ^~~~~
subsequence.cpp:56:35: note: in expansion of macro 'fi'
   56 |             ans.fi = next[ans.fi].fi;
      |                                   ^~
subsequence.cpp:10:12: error: request for member 'second' in 'next[ans.std::pair<int, int>::second]', which is of non-class type 'std::pair<int, int> [(n + 1)]'
   10 | #define se second
      |            ^~~~~~
subsequence.cpp:57:35: note: in expansion of macro 'se'
   57 |             ans.se = next[ans.se].se;
      |                                   ^~