제출 #1277110

#제출 시각아이디문제언어결과실행 시간메모리
1277110Bui_Quoc_CuongCollecting Stamps 3 (JOI20_ho_t3)C++20
100 / 100
223 ms205124 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 ll long long
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define BIT(mask,i) ((mask>>(i))&1)
#define MASK(a) (1LL<=((a)))
#define uni(v) sort(all(v)); v.resize(unique(all(v)) - v.begin())
#define pii pair <int, int>
#define vi vector <int> 
#define vl vector <ll>
template <class A,class B>
bool maximize(A &a, const B b)
{
    if(a < b){ a = b; return 1;} return 0;
}
template <class A,class B>
bool minimize(A &a, const B b)
{
    if(a > b){ a = b; return 1;} return 0;
}
const int maxn = 200 + 5;

int n, L;
int X[maxn], T[maxn];
int dp[maxn][maxn][maxn][3];

int dist(int x, int y)
{
	return min(L - abs(x - y), abs(x - y));
}

void solve()
{
	cin >> n >> L;
	FOR(i, 1, n) cin >> X[i];
	FOR(i, 1, n) cin >> T[i];
	memset(dp, 0x3f, sizeof dp);

	X[n + 1] = 0;

	dp[n + 1][0][0][0] = 0;
	queue <array <int, 4>> que;
	que.push({n + 1, 0, 0, 0});

	int ans = 0;
	while(!que.empty())
	{
		int l = que.front()[0], r = que.front()[1], cnt = que.front()[2], t = que.front()[3];
		int curT = dp[l][r][cnt][t];
		que.pop();	
		maximize(ans, cnt);
		// mo rong l
		{
			int newl = l - 1;
			if(newl <= r) continue;
			int newT = (t == 1 ? dist(X[r], X[newl]) : dist(X[l], X[newl])) + curT;
			int newcnt = (newT <= T[newl]) + cnt;

			if(minimize(dp[newl][r][newcnt][0], newT))
			{
				que.push({newl, r, newcnt, 0});
			}
		}
		{
			int newr = r + 1;
			if(newr >= l) continue;
			int newT = (t == 1 ? dist(X[r], X[newr]) : dist(X[l], X[newr])) + curT;
			int newcnt = (newT <= T[newr]) + cnt;

			if(minimize(dp[l][newr][newcnt][1], newT))
			{
				que.push({l, newr, newcnt, 1});
			}
		}
	}


	cout << ans;
}		

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);    
    #define kieuoanh "joi20_ho_t3"
    if(fopen(kieuoanh".inp","r"))
    {
        freopen(kieuoanh".inp","r",stdin);
        freopen(kieuoanh".out","w",stdout);
    }
    int tst = 1; 
    // cin >> tst;
    while(tst--) solve();
    return 0;
}

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

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